27

I have this activity that lists some information which I provide a refresh button for. The way I'm refreshing it (probably not the best way by any means) is just launching the activity all over again. To make the back stack work the way I need it to I need to pass in the FLAG_ACTIVITY_CLEAR_TOP flag to the intent and it works fine. But to give the illusion that the information is refreshing the information within the activity and not completely relaunching it, I also need to add the flag FLAG_ACTIVITY_NO_ANIMATION. So far, I haven't been able to get these two flags to work together. I've tried the following methods:

theIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION+Intent.FLAG_ACTIVITY_CLEAR_TOP);
theIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION|Intent.FLAG_ACTIVITY_CLEAR_TOP);

theIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
theIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Clear top works correctly for all of them but the animation is still there. Any help would be greatly appreciated.

4 Answers 4

60

Use operator | to set multiple flags

theIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION|Intent.FLAG_ACTIVITY_CLEAR_TOP);
2
  • @100Kg,lances try applying <style name="noAnimTheme" parent="android:style/Theme.NoTitleBar"> <item name="android:windowAnimationStyle">@null</item> </style> to your activity in manifest: <activity android:name="com.me.myproject.MyActivity" android:theme="@style/noAnimTheme" />
    – Saqib
    Apr 16, 2013 at 22:34
  • 1
    Why it has to be or instead of and. How does this work? Jan 24 at 8:16
40

For folks that may be making an Android app in Kotlin

coolIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
3
  • Thanks, didn't realize I was using Kotlin in that part...
    – Inoy
    Oct 14, 2022 at 19:52
  • How does this work? It seems like it should be and, doesn't it? Jan 24 at 8:16
  • because it's a logical or operation, It's not same as ||. It's or because you want to sum the bits (to end up with 1s if either is 1)
    – Javad
    Aug 24 at 20:46
10

Use addFlags() so that you can add multiple number of Flags to Intent.

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
3

You might try using

overridePendingTransition(0,0);

immediately after calling startActivity();

1
  • I used but now it show black screen first and then target one.
    – RobinHood
    Nov 18, 2013 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.