I have an application that has an initial activity (A - also the one specified in the launcher) from which it allows the user to launch another activity (B). I am saving the state of Activity B (onSaveInstanceState() and restoring it in onCreate()).
On some phones (N1 and Motrola Milestone as of now but not the Galaxy S) after launching B if the user presses the home button (i.e. app goes to background) and then immediately re-launches the app, they are shown activity A again (not B). But if they launch it from the 'Recent' apps (Home button long press) they are taken to the activity B.
From what I understand of the Android docs, unless the task has been killed (doesnt seem like the case here as nothing else is done except re-launch the activity from the app screen) we should see activity B restored on launch (as that is on top of the stack). So I just can't seem to figure out what the heck is wrong here.
BTW orientation changes during app usage works fine (everything saves and restores fine). This weird problem has been bugging me for some time now and by trial and error I discovered that when I disabled orientation for that activity and then trying the re-launching got B to show as expected.
So has anyone else faced something like this and if so how can this be resolved?
I am looking into saving the running activity in SharedPreferences (as mentioned in this post) and they restoring it from that in activity A, however would like to know if I am missing something here. Shouldn't having B restored on re-launch be the default behavior?
In your AndroidManifest, in the activity tag, just add
This answer is for someone coming from search engine due to similar kind of issue.
I had,
Always starts A after pressing
HOME
button or Switching from task list when application was in B.Finally found that the problem was in manifest, removed
android:noHistory = "true"
from Activity declaration of B in manifest and it was resolved.
Use android:launchMode="singleInstance" instead
This is because another instance of app is launching when icon is pressed.
write the above code in your launcher activity before calling setContentView. This will solve the problem
Try adding this to your activity inside the manifest file:
This resolved the issue in my app .... if I understand your problem correctly.