The application that I am developing has a weird behavior the first time that it is installed. If the user backs out of the application normally the first time, it will fore
Why this is behaving, no clue. But I know that custom Launcher
have specific launchModes
set.
For example the ADW.Launcher:
android:clearTaskOnLaunch="true"
android:launchMode="singleTask"
Home application in the Android SDK samples: android-sdk\samples\android-16\Home\AndroidManifest.xml
android:launchMode="singleInstance"
To quote CommonsWare: How to prevent custom home launcher app restart activity?
I am going by the Home sample application from the SDK, which uses singleInstance. Curiously, the AOSP launchers use singleTask
Welcome to the ever-growing list of users who have been bitten by this one.
This is a well-known and long-standing Android bug. in the way applications get launched the first time from the installer, web-browser and via IDE (IntelliJ, Eclipse, etc.). See these issues filed long ago related to the problem:
http://code.google.com/p/android/issues/detail?id=2373
http://code.google.com/p/android/issues/detail?id=26658
It is still broken and you cannot prevent this from happening. The only thing you can do is to detect when Android has launched a second instance of your root activity into an existing task. You can do this by putting this code in onCreate()
of your root activity:
if (!isTaskRoot()) {
// Android launched another instance of the root activity into an existing task
// so just quietly finish and go away, dropping the user back into the activity
// at the top of the stack (ie: the last state of this task)
finish();
return;
}
Looks like the issue is caused by the different instances of the app. Probably the first instance is launched under the installer's task and the second one is under its own task, when user clicks on app icon. It seems to user he/she resumes the app but actually he launches it again at this moment.
If you want to get your app to run in its own task only, a possible way is to add
android:allowTaskReparenting="true"
to the application-level of your AndroidManifest. Once the app icon is clicked for the first time after installation, your application will be moved to the separated task.