Animation Doesn't Work

Intent intent = null; intent = new Intent(this, A.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); overridePendingTransition(R.anim.no_animation, R.anim.slide_down_out); ClassSelector.this.finish(); startActivity(intent); 

I need to go from the current page to another page, that is A. I added the code 'intent.addFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);' since this code applies, the animation that applies to A does not work.

+4
source share
3 answers

two flags

 Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK 

have the opposite intention. One brings the old activity from above, and the other creates a new task that may have results that cannot be predicted.

 Intent.FLAG_ACTIVITY_SINGLE_TOP 

which can bring you the necessary animation.

+3
source

You can call finish() in your activity right after calling startActivity() (and get rid of your flags), and then in this new action in the onBackPressed() method call this code:

 @Override public void onBackPressed() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } 
+1
source

You just need to place an overridePendingTransition call after startActivity.

Example:

  Intent intent = null; intent = new Intent(this, A.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK); ClassSelector.this.finish(); startActivity(intent); overridePendingTransition(R.anim.no_animation, R.anim.slide_down_out); 
0
source

All Articles