Steps to reproduce the problem.
- Create or dowload any application with several activities.
- Load apk file to sdcard or install from market.
- Install appliaction using standard App Manager.
- After installation in App Manager press Open or press on notification message after downloading.
- After application running go to the next (the开发者_JAVA技巧 second) application screen.
- Press HOME.
- Press application icon.
What happened.
Appliaction is restarting from the first screen and does not retain the second screen. Application retains activites in normal way after application restart or if you pressing BACK button in application to home screen.
- Correct behavior should be.
Application must always retain activites in normal way.
How can I solve this problem for my application? Can I restart application during first run?
Depending on how the application is defined in the manifest file and whether it has any mechanism to save and restore its state....
Based on your steps, it might create several instances of the same application (check this)
Or it is not using the instance Bunble in onCreate
It is definitely not going to be automatic for all applications to come back to the save screen it was at when it was paused or destroyed (some application do not want that, think about your bank account management...)
Edit :
So if I understand correctly from your comments, it works as you expect when you quit the application with the BACK key, but not when you use the HOME key...
Read the link I posted : http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html
You will understand that when you press the HOME key, the instance of your application you were in is not destroyed (and so the current state is not saved). Starting it again only starts another instance (from the initial screen).
When the user presses the BACK key, the current activity is destroyed and the previous activity resumes.
...
A task is a cohesive unit that can move to the "background" when users begin a new task or go to the Home screen, via the HOME key
If you want to change the way it behaves, look at the launchMode
in the manifest.
I think that App Manager runs my application in wrong way. It runs my applications in its task. When I press HOME and press application icon I runs second task with my application.
I tested it. I made two applications App1, App2. App2 has two activities A and B. App1 runs App2 in the simplest way.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("org.app2.test", "org.app2.test.Screen1"));
Test 1. Run App1. App1 runs App2 activity A. Acctivity A runs activity B. Press Home. Press App2 icon. You can see App2 activity A.
That I changed code for launching App2.
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName("org.app2.test", "org.app2.test.Screen1"));
Test 2. Run App1. App1 runs App2 activity A. Acctivity A runs activity B. Press Home. Press App2 icon. You can see App2 activity B.
精彩评论