Added the answer that antonyt provided: Override protected void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); if ((getIntent().getFlags() & Intent. FLAG_ACTIVITY_BROUGHT_TO_FRONT)!
= 0) { // Activity was brought to front and not created, // Thus finishing this will get us to the last viewed activity finish(); return; } // Regular activity creation code... }.
Added the answer that antonyt provided: @Override protected void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); if ((getIntent().getFlags() & Intent. FLAG_ACTIVITY_BROUGHT_TO_FRONT)!
= 0) { // Activity was brought to front and not created, // Thus finishing this will get us to the last viewed activity finish(); return; } // Regular activity creation code... }.
The underlying issue I believe is that the Intents used are different between the launcher and the installer. In so far as you are getting different Intent flags you are going to get different launch behavior. You can muck with the launch modes and you may be able to get a consistent result but fundamentally those different Intents will produce different results.
Your fix (or something like this) is probably your best bet.
This seems like a fundamental problem that many apps would find undesirable - indeed, I have seen the Android Facebook app exhibit this behaviour - and so it is quite disappointing that the above workaround (or similar) is all we can do. – antonyt Jun 18 at 17:31 It could be considered a behavior defect: on the other hand, it does allow you to differentiate between Installer launches and App icon launches, which you could use to launch a Welcome screen that only shows up when someone clicks on the Installer run button. Now that I think about it I might actually use that :) – Femi Jun 18 at 17:53 @Femi However, keep in mind that not everybody will start the app for the first time via the Install & Run option, and they may still appreciate a greeting when they get around to it.
:) – Glendon Trullinger Jun 18 at 18:47 Very true: I already have logic in my apps to check the first run, this is just one more hook. – Femi Jun 18 at 18:56 I have tried to detect whether or not the category is set in the intent used to start the activity (it usually isn't set by the installer, only the launcher) - if it is missing I add the category and the flag and then restart (startActivity()/finish()) with this modified intent. The bad behaviour still occurs even though the intents now seem to match.Do you have any thoughts on this?
– antonyt Jun 18 at 19:34.
Your problem is likely rooted in the fact that App installer doesn't use the LAUNCHER category, as does the launcher. This bug has been documented elsewhere: App always starts fresh from root activity instead of resuming background state (Known Bug).
For testing purposes only, I am allowing my app APK to be downloaded and installed via a URL. Once downloaded on the phone, it can be launched with the Android app installer which gives the user an option to install it to their device and then run it. Consider if we downloaded and ran the app in the way described above.
The main/launcher activity in my app is a login page (Activity A). Once the user is authenticated, they are taken to the main area of the application, e.g. So now the current activity stack of this task is A > B. I then press the home button on the phone and am taken to the Android home screen.
I re-launch my app via the icon in the menu, and I am taken to Activity A, instead of Activity B. Either the activity stack is now A > B > A, or there are now two separate tasks with activity stacks A > B, and A respectively. What I want is to be taken back to Activity B when I relaunch the app.
Pressing back whilst in this state will take me back to Activity B. This undesired behaviour only happens if I first open the app via the installer, and not if I open the app via the home screen/menu. I looked into how the activities are being started by each mechanism.
When started with the installer we see it is using the flag 0x10000000, but when started with the launcher we see it is using 0x10200000. It is also using an intent category. The flag FLAG_ACTIVITY_RESET_TASK_IF_NEEDED (which is being used when the app is launched from the launcher) seems to usually prevent a new task from being created if one already exists, and will restore the last used activity.
This is the desired behaviour. Why is it not working in this situation? Is there anything I can do to make sure my application will always return me to the last Activity regardless of whether it was started through the app installer/launcher?
If I use singleTask it will always take me back to the main activity (Activity A) whenever I run the app (which is also not desirable). Here is a question I found where someone is experiencing a similar problem (which has no accepted answer): App loses its ability to remember its stack when launched from another application. EDIT: Checking for the flag FLAG_ACTIVITY_BROUGHT_TO_FRONT in onCreate() of our launcher activity (and then finishing if it is set) seems to fix the main symptom, but clearly the underlying issue is still there.
Is there a more complete fix? EDIT2: The same result occurs when you download/run the app from the Android Market, so some of the above details may not be relevant.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.