I am working on a fitness app which has a home activity which launches a workouts activity which launches a specific workout activity. In the workout activity, one may start a workout. Thereafter, one might want to then press the Home button and launch a music player or perhaps the web browser. At some point, one would probably launch the app again to return to the already running workout, but that ends up launching a new instance of the app. When I set the launchMode on the home activity to singleTask, it simply goes back to the existing home activity when I tap the launcher icon. What I would like is for it to go back to the workout in progress, which is where you would depart the app.

Essentially, I'm looking for behavior identical to iOS where it would simply restore the app to its current state if you "relaunched" the app and it was still running.

有帮助吗?

解决方案

It is supposed to work as you've described. In most cases, it actually does work like that. However, there is a long-standing nasty Android bug which causes the behaviour you've described. This happens when you launch the app for the first time from an IDE (like Eclipse) or by clicking the "open" button on the Installer screen. To see if this is what you're seeing, just do this:

  1. Go to Settings->Applications, choose your app and click "Force close"
  2. Launch your app, do something, press the HOME button
  3. Launch your app again.

You should return to where you left off. If not, something else bad is going on. If that is the case, please post your manifest in your question, because the problem is likely in these.

Don't try to use special launchModes to fix this. This just creates more problems.

See this answer for more information about the nasty long-standing Android bug.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top