5

I have an Activity with launchmode = "singleInstance" and it is the launcher Activity of the app. Now I am trying to detect which Flag my Activity was/will be launched with, but I can not find the flag id with the Intent Flags on the documented page; this is the flag

String version of the Flag id is 270532608

and String version of the Intent is

04-25 20:18:57.061: V/logtag(1665): Intent { act=android.intent.action.MAIN 
        cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=<filtered> }

when the application first starts, the system calls my Activity with this Flag = Intent.FLAG_ACTIVITY_NEW_TASK or string version = 268435456 (which it should) but when I quit the app, and start it once more from the launcher I get this flag 0x10200000 instead of the previous flag

so my question is can anyone tell me what Flag this is?

and why my activity is being called with it?

and are there any other instances from the launcher that my activity might be triggered with a different flag aside from the unknown one & 0x10200000?

Community
  • 1
  • 1
Elltz
  • 10,730
  • 4
  • 31
  • 59

2 Answers2

12

It's a combination of the flags:

public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;

and

public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;

0x10000000 is the hexadecimal notation for 268435456.
0x00200000 is the hexadecimal notation for 2097152.
If you add these numbers, you get:
0x10200000, which is the hexadecimal notation for 270532608.

So the first time you start your app, you just get FLAG_ACTIVITY_NEW_TASK, but the second time you will also get FLAG_ACTIVITY_RESET_TASK_IF_NEEDED. This is just a bitwise OR operation. To check if your desired flag is active, you can do a bitwise AND like this:

boolean hasNewTaskFlag = (flg & FLAG_ACTIVITY_NEW_TASK) != 0;
Endran
  • 1,627
  • 1
  • 10
  • 15
  • Omg!! Sir? if i may ask, do you know this by experience or there is some source, i am not doubting you, i just need to be informed so as i can be able to detect combinations as you pointed out? btw you have my upvote – Elltz Apr 26 '15 at 10:30
  • 1
    All of the flags cam be seen in the documentation at http://developer.android.com/reference/android/content/Intent.html – Endran Apr 26 '15 at 10:42
  • You just need to do bitwise operations to see which flags are active. – Endran Apr 26 '15 at 10:43
1

First of all, this flag 0x10200000 value is in Hexadecimal not in Decimal that's why you might not find any useful info if you tried to Google it.

That's why you have to convert it first to Decimal. Then you will see that the real flag value is 270532608 which means start a new task over the previous one

why my activity is being called with it?

Because you probably resuming the instance that was in the background (Recent app list). Not starting a new instance

If you want to read more about this intent flag click here

reference: Start new activity in window manager

Community
  • 1
  • 1
Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66
  • so if i had `excludefromrececents = true;` there will be chance that i would not get this flag? i am trying to catch scenarios Sir, and it's because of the `singleinstance` right? what if i had `singletask`? but i think even though i did not pay attention to it, that my activity with its task did finish. and quick catch i was not googling for the hexadecimal number (: just a word out, – Elltz Apr 26 '15 at 10:36
  • Using `android:noHistory = "true"` will let you get that flag again if you back press with your launcher activity and relaunch again. – TheLittleNaruto Apr 26 '15 at 10:50
  • yes but on this activity i spark startActivityforResult & with that i would not get my return intent, so i excluded it from my options @TheLittleNaruto but thanks Sir, – Elltz Apr 26 '15 at 10:59
  • Okay , so now you say that, that makes sense. There can be other way too, like you can call `finish()` as soon as your launcher activity has done the job.And relaunching the launcher activity thereafter will reproduce the same flag. :-) – TheLittleNaruto Apr 26 '15 at 11:02
  • @Elltz you have to give them a try or you can simple handle this `Intent` value and do a specific action for it – Sami Eltamawy Apr 26 '15 at 11:40