2

Background

I have a very weird situation that i've never seen on any app i've created .

The app has multiple activities , while the first one is used for some initializations and for the splash screen .

The problem

Suppose the app has the activities "A", "B", "C" ,... , and the end user goes from "A" (the first one , of the splash screen) to "B" , and then presses the home key , and returns to the app by clicking its icon on the launcher .

In short ,scenario is :

app launched -> activity A (splash) -> activity B -> pressed on home -> returned to app (via the launcher) -> ?

Expected result : the app should return to the last activity that was shown , meaning that "?" = activity B

The actual result : the app actually returned to activity "A" , meaning that "?" = activity A , and after that , to the activity that i've left it (in this case , B )

There is not much to show in both the manifest and the code , since they are all very standard .

Clues for solving the problem

However , there are some clues that might tell something about the cause of this:

  1. each activity might take some memory for showing images, but they are not taking a lot.

  2. all activities extend from the roboSherlock activities variants , including the splash screen activity that extend from RoboSplashActivity .

  3. On the first activity (the splash screen) , i didn't let the call to super.andFinishThisOne(); within the andFinishThisOne method , since i need to initialize more things other than the roboguice injections . However , when everything is ready , i start the new activity and closes the current one using finish() .

  4. There is a bug report (here) that describes a similar scenario . Not sure how similar , and what can be done to handle it.

What i've tried so far

I've tried the next solutions so far:

  1. Playing with different flags and properties for the first activity (mainly the launchMode ) in the manifest but none helped the situation.

  2. used startActvityForResult on the splash screen activity , without calling finish() . it also didn't work and re-created the activity .

for now , i've simply added the next code to skip the first activity in case it's not the root activity , but that's more like a workaround than a real solution.

if (!isTaskRoot()) {
    finish();
    return;
}
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • I don't know why you're having the specific issue, but it could be something to do with RoboSplashActivity, which I've never used - so I don't know. The one comment I have however is do be careful about using one Activity to initialise state data on which a subsequent Activity relies, because it is entirely possible (and very frequent) for the Activity stack to be resumed but with all memory and state killed, including the Application class and other singletons / static data. – Trevor Feb 13 '13 at 15:52
  • I know , the splash screen activity is the main suspect of this problem. However , how could they enforce a special (and weird) behavior on android itself ? I mean , how would they make it work such that this activity keeps being recreated as the first one ? seems very odd to me , especially since everything is already initialized when going back to this activity . – android developer Feb 13 '13 at 18:49
  • If the launcher launches A, than A will be created when you press it. No matter where you left the app before... – WarrenFaith Feb 14 '13 at 11:19
  • then how come it returns after the splash screen to the exact activity i was before? also , i think it has something to do with how you set your app . try out facebook app for example , and go there into the settings screen . then press on HOME and return to the app via the launcher . – android developer Feb 14 '13 at 11:44
  • @WarrenFaith , you are wrong , and you can check it out yourself . create a totally new app with 2 activities , each shows a different toast on the onCreate method , while the first activity starts the second activity right after showing the toast . then press HOME , and click the icon of the app in the launcher . – android developer Feb 14 '13 at 11:51
  • If this only happens after you have started the app initially from the installer, you are probably seeing this: http://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508#16447508 To test this, make sure you exit the application (or kill it), then start it again from the list of available apps (by clicking on the icon) and see if the behaviour is still the same. – David Wasser May 18 '13 at 18:48
  • @DavidWasser this is a very weird bug and i was sure i could do something in the manifest for solving it. it's an old post and i don't remember the exact way to do it (and actually can't reproduce it). maybe it was all because i used roboguice. it has weird bugs in it. – android developer May 18 '13 at 18:59

0 Answers0