开发者

Start a new activity with no transition animation in android 1.6

开发者 https://www.devze.com 2023-01-30 17:25 出处:网络
I am aware that from API level 5 it is possibl开发者_开发百科e to specify a flag in the intent to prevent the normal animation being applied when I start a new activity:

I am aware that from API level 5 it is possibl开发者_开发百科e to specify a flag in the intent to prevent the normal animation being applied when I start a new activity:

myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

However, my question is: is there a way to achieve the same thing in an app supporting android 1.6?


On the newer versions, you want to override the transition with 0,0 shortly after you start the activity:

Intent i = new Intent(this, YourNewActivity.class); 
startActivity(i);
overridePendingTransition(0,0);

I tried this on 2.1 and 4.0.3, it worked for me. =)

I found it in the docs here


Use this: getWindow().setWindowAnimations(0); within the Activity that is starting.


This solution worked for me (Android 2.2):

Intent intent = new Intent(getContext(), YourClass.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
getContext().startActivity(intent);


FYI, I'm on 4.4.2 and these are the only things I found that work:

To prevent the opening animation: in the launching activity's onCreate(), add overridePendingTransition(0,0).

To prevent the closing animation: after finish(), immediately call overridePendingTransition(0,0).

These DON'T work (at least not on my 4.4.2 build): (1) calling getWindow().setWindowAnimations(0) in onCreate() (passing in a non-zero number DOES work, but that's an ugly hack since it's expecting a resId), and (2) calling overridePendingTransition(0,0) immediately after startActivity() -- animation is still present.


put below code on onCreate of Activity:

getWindow().setWindowAnimations(0);
0

精彩评论

暂无评论...
验证码 换一张
取 消