Disable Transition Animation Between Activities - java

I am calling an Activity B from Activity A, which contains a Video View using the following code :
Intent intent = new Intent(this, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, 0);
I am using Intent.FLAG_ACTIVITY_NO_ANIMATION to avoid transition animation while new activity is being called. But its not working for me and a black screen is coming while the transition. Is there any way to avoid this transition animation and black screen, so that the user will not come to know that the video view is being called in a new screen?

Try calling:
Intent intent = new Intent(this, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, 0);
overridePendingTransition(0,0); //0 for no animation

if you want to do it for all activities then do it in this way:
switching activities without animation
Just assign style with no animation to each activity in manifest.
Or through code do it in this way:
Disable activity slide-in animation when launching new activity?

Took me quite some time to figure it out...
to support overriding transition when coming back from another Activity:
use overridePendingTransition in your Activity onResume.
override fun onResume() {
super.onResume()
// disable transition when coming back from an activity
overridePendingTransition(0, 0)
}

Related

OverridePendingTransition doesnt work if i will use intent

I'm trying to open an already activity with animation open.
It will run it only first time which activity starts and then it will not work again
Here is the code :
var intent = new Intent(this, typeof(TableItemsMain))
.SetFlags(ActivityFlags.ReorderToFront);
StartActivity(intent);
OverridePendingTransition(Resource.Layout.trans_left_in, Resource.Layout.trans_left_out);

Moving of image between ImageButtons in seperate Activities onClick Bitmap

So 1 have 2 ImageButtons, clothesButton1 with an image declared in xml, and imageButton2 which is blank. Both are in seperate activities.
Upon clicking clothesButton1, i want to move the image in clothesButton1 to imageButton2 using Bitmap. clothesButton1 will become blank afterwards.
Here's my code in Java for clothesButton1:
final ImageButton clothesButton1 =(ImageButton)findViewById(R.id.clothesBtn1);
clothesButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
clothesButton1.buildDrawingCache();
Bitmap bitmapclothes = clothesButton1.getDrawingCache();
Intent intent = new Intent();
intent.putExtra("BitmapClothes", bitmapclothes);
}
});
In my second activity (for imageButton2):
final ImageButton imageButton2 = (ImageButton)findViewById(R.id.imageButton2);
Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapClothes");
imageButton2.setImageBitmap(bitmap);
However the moving function isn't working and I really have no idea where I am wrong. Any help is greatly appreciated.
The error is because of Intent. There are two types of Intent in android Explicit and implicit intents. When you create an Intent with a Context and a Class object, you are creating an explicit intent. You use explicit intents to start activities within your application.When an activity in your application wants to start an activity in another application, you create an implicit intent. In Your case it is Explicit Intent use Intent intent=new Intent(getApplicationContext(), secondActivityName.class).
In your case
Intent intent=new Intent(getApplicationContext(),secondActivityName.class);
intent.putExtra("BitmapClothes", bitmapclothes);
startActivity(intent);
To understand more about intent read this tutorial.
I think the problem is that you didn't enabled the drawing cache on clothesButton1.
clothesButton1.setDrawingCacheEnabled(true);
Please refer:https://developer.android.com/reference/android/view/View.html#getDrawingCache%28boolean%29
I think that you can achieve this easily with Activity Transition. Take a good look at it :)
The Start an activity with a shared element section might be what you want.
First,getDrawingCache() returns null;second the way you invoke other activity is not correct!
try this :
clothesButton1.setDrawingCacheEnabled(true);
clothesButton1.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
clothesButton1.layout(0, 0, clothesButton1.getMeasuredWidth(), imageButton.getMeasuredHeight());
clothesButton1.buildDrawingCache(true);
Bitmap bitmapclothes = Bitmap.createBitmap(clothesButton1.getDrawingCache());
clothesButton1.setDrawingCacheEnabled(false);
Intent intent = new Intent(NowActivity.this,SecondActivity.class);
intent.putExtra("BitmapClothes", bitmapclothes);
startActivity(intent);
Reference:Android View.getDrawingCache returns null, only null

Android Java, onfinish(); moves me in an activity

I have three activities (a, b, c).
Activity a
- has one button for activity b and one button to close the app (by calling onfinish()).
- is the main activity, which runs b.
Activity b
- is the middle one which runs c.
After clicking on a back button that I placed in the header of activity c, and then clicking on the button of the a activity to close the app, I am returned to activity c. This is not the behavior I expected, any ideas about what is happening?
Further information:
activity c has onResume() because I also have an activity d. so when I click back button of activity d, it returns to activity c.
so long as I don't run the activity c, the close button works as expected.
try this.
Intent intent = new Intent(getApplicationContext() or UrActivity.this, FirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
For going previous activity just call
finish() ;
at back button of any activity .don't do this
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
and from exiting the application use
Intent intent = new Intent(getApplicationContext(), a.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Clearing Activity Stack on Intent Start

I have an app that I'm writing that starts with an initial Login/Create New Account splash screen. In onCreate it checks my SharedPreferences to see if user credentials are stored. If they are the activity launches an intent to the main activity skipping the login/create process.
if (haveCredentials()) {
Intent i = new Intent(this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
I don't want the user to be able to go back to the splash screen. As you can see I'm trying the CLEAR_TOP Intent flag as suggested by this but it doesn't seem to be working. Not sure what I'm missing.
Current State of the Activity Stack
SplashActivity->MainActivity
Desired State of the Stack
MainActivity
Have you tried finishing the current activity?
if (haveCredentials()) {
Intent i = new Intent(this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish(); //add this!
}
Just use finish() after startActivity(), so that when back button is pressed the previous activity will not be shown.

finish current activity and start another activity when screen being off (black)

i have developed application that consists of A activity (luncher), B activity (second), C activity (third),
what i have tried is :
when the screen is locked or turned off as you are away from the device or have pressed the power button to locked it, my goal is C activity finished and when you turn the screen on again A activity start.
Note : i'm new to android and java development .
i think we can use onPause(), method or onStop(), method for that purpose, but it acually does not work with me as below code in C activity :
protected void onPause(){
super.onPause();
Intent i = new Intent(this,A activity);
startActivity(i);
}
when i lock screen and it become black then open again it still has C activity there.
any advice to get that with onPause(), method or onStop(), method or other ways to get it, thanks
in C Activity - onPause method you can try using this code:
new Handler().post(new Runnable() {
#Override
public void run()
{
Intent intent = new Intent(this,A activity);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
overridePendingTransition(0, 0);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
}
this will close current activity and open selected activity.
Hope it helps.
I am not sure but try this way:-
protected void onPause()
{
Intent i = new Intent(this,A activity);
startActivity(i);
super.onPause();
}

Categories

Resources