Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between opening an app from the applications screen and the recently used apps list? (android

Can anyone tell me what the difference is between opening an app from the applications screen and opening it from that recently used apps list that pops up when you long-press the home button?

I didn't even know that recently used list existed until a friend managed to break my app by launching it from there. He tried twice and got the same force quit, but when he launched it from the applications screen it opened fine.

The error log told me that a nullPointerException occurred in the getCount method on my ArrayAdaptor for my ListView.

Anyway I just wondered if there was a difference that I need to know about and adapt my code to deal with?

like image 537
Emma Assin Avatar asked Dec 01 '11 21:12

Emma Assin


2 Answers

AFAIK, If your application is completely shutted down, launch from applications screen and recently used apps list should have no difference, both refresh start your application and open your application's MainActivity (by stack-push your application's MainActivity into a newly created task)

However, as Android is multi-task OS, your application can be put into background in standby mode i.e. open your application then short-press home button, this is not same as press back button. If you haven't override these key pressed in your application, press back button several times with pop all your activities off from activity stack and finally kill your application, whereas press home button will bring System's HomeActivity into foreground hence flip your application (AKA. task with activity stack) into background.

Things becomes more interesting here, depend on which value your configure your activity's android:launchMode in AndroidManifest.xml, if you use standard or singleTop:
1. launch app from recently used apps list always bring your standby activity back to foreground, i.e. re-order activity stack.
2. launch app from applications screen will create a new instance of your MainActivity and open it, i.e. push a newly created MainActivity into activity stack, so now you have two instances in your application's activity stack

If you use singleTask or singleInstance:
2. launch app from applications screen will use the standby MainActivity (if exist) in your application's activity stack and re-open it, i.e. re-order activity stack.

Checkout Tasks and Back Stack to see how different configurations may affect your application's activity stack behaviour.

like image 87
yorkw Avatar answered Oct 21 '22 15:10

yorkw


I believe there should be no difference. These are the lifecycle methods I typically see when pressing the home button from an activity, on android 2.3.4

onPause
onStop

then when I use either the icon or previous applications to navigate back, I see

onRestart
onStart
onResume

Now, in some cases the system will tell your activity to finish while you are away (or immediately when you return if an orientation change occurred). Then you will see onDestroy, and the following when you navigate back

onCreate
onStart
onResume

I don't think there is anything mysterious going on here. According to the Activity documentation, there are only four states that a process can be in, and both of these fall under background activity.

like image 30
skynet Avatar answered Oct 21 '22 17:10

skynet