开发者

Save activity gui state

So I'm writing an app. I would like to be able to press the home key to leave the app, do something else for a moment, then come back to the app by picking it from the launcher. I want the app to have exactly the same state as it did when I left it. To this end, I have implimented onSaveInstanceState() to create a bundle, and I use this bundle in onCreate() (checking if it is null, of course).

This is what I would expect to happen...

-I install the app from Eclipse

-I launch the app from the launcher

-I press the home key

-onSaveInstanceState() is caled, I write a bundle

-I launch the app again from the launcher

-onCreate() is called, I get the bundle I previously wrote

-I use that bundle to restore my ui

This is what happens though... -I install the app -I launch the app from the launcher

-I press the home key

-onSaveInstanceState() is called, bundle is written

-I launch the app again

-onCreate() is called WITHOUT my bundle

-What appears to h开发者_运维问答ave happened is that a new activity has been put onto the stack for this task.

-I press the back button

-The activity I just launched is destroyed, and the activity i launched first is displayed, with the correct state!

-Repeat pressing back until back at the homescreen

-The lifecycle now works as expectecd! Even after a reboot, but it fails when I install a new version of the app

What could possibly be doing this, ONLY after installation!


A few people have asked very similar questions on here in the past month or so.
You need to make sure that Eclipse does not handle any Activity launching.

Edit your Launch Configuration in Eclipse to change "Launch Action" from "Launch Default Activity" to "Do Nothing".

Or you can install the APK manually.


Gah, here's the problem.
http://code.google.com/p/android/issues/detail?id=2373
When launching the app from eclipse, it bugs out as i described. Creating an apk and doing "adb install ...apk" and it works exactly as expected

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜