Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple flags to an intent in android

Tags:

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.

like image 289
lancex Avatar asked Feb 10 '12 05:02

lancex


People also ask

How do you add multiple flags to intent?

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

How do you add multiple flags intent in Kotlin?

In Kotlin or is the replacement for the Java bitwise or | . If you need the option to add additional flags in other situations, add an optional param to the extension function.

What are intent flags in Android?

There are flags which you can use in this time depending on your requirement. Here is how they work : FLAG_ACTIVITY_CLEAR_TASK - If set in any intent that is passed to your startActivity(), it will cause any existing task that would be associated with the activity to be cleared before the activity is started.


1 Answers

Use operator | to set multiple flags

theIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION|Intent.FLAG_ACTIVITY_CLEAR_TOP); 
like image 50
jeet Avatar answered Oct 26 '22 17:10

jeet