Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch activity without animation in Android?

How can I use properly the Intent flag FLAG_ACTIVITY_NO_ANIMATION in AndroidManifest file? I supose my problem is trivial, but I can't find good example or solution to it.

    <intent-filter>         <data android:name="android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION" />     </intent-filter> 

However no error is reported by compliator, but data isn't correct. I just want to disable animation in case switching between activities. I can use getWindow().setWindowAnimations(0); in onCreate or onResume rather but using flag is better way, isn't it?

I can use also in code:

    Intent intent = new Intent(v.getContext(), newactivity.class);     intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);     getContext().startActivity(intent); 

But I want to use this flag in Android Manifest. To disable animation also in case returning from second activity to first.

like image 395
woyaru Avatar asked Aug 07 '11 10:08

woyaru


People also ask

How do I turn off activity animation?

To disable the similar animation that is triggered when calling finish() on an Activity, i.e the animation slides from right to left instead, you can call overridePendingTransition(0, 0) after calling finish() and the next animation will be excluded.


2 Answers

You can create a style,

 <style name="noAnimTheme" parent="android:Theme">    <item name="android:windowAnimationStyle">@null</item> </style> 

and set it as theme for your activity in the manifest:

   <activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">     </activity> 

You can also define a style to specify custom entry and exit animations. http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation

like image 85
Santosh Avatar answered Sep 19 '22 10:09

Santosh


If your context is an activity you can call overridePendingTransition:

Call immediately after one of the flavors of startActivity(Intent) or finish to specify an explicit transition animation to perform next.

So, programmatically:

this.startActivity(new Intent(v.getContext(), newactivity.class)); this.overridePendingTransition(0, 0); 
like image 37
eshirazi Avatar answered Sep 18 '22 10:09

eshirazi