Intent intent = new Intent(context, LoginActivity.class); //添加intent标志符,清理task栈,并且新生成一个task栈 //这样做会引起Activity之间过度动画错误 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); //优化:定义activity跳转动画 ((Activity) context).overridePendingTransition(R.anim.open_enter, R.anim.open_exit);
//------------------------------
<!--open_enter-->
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <!--新进入的activity--> <translate android:duration="@integer/anim_duration" android:fromXDelta="100%" android:toXDelta="0%"></translate> </set>
<!--open_exit-->
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:duration="@integer/anim_duration" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:toXScale="0.8" android:toYScale="0.8"></scale> </set>