Reputation: 1108
So I have read that there are four launch modes for an Activity in Android as follows
1) standard : create a new instance of an activity every single time.
2) single top : same as standard except that if the activity is at the top of the stack, then the same instance will be used.
3) single task : a new task will be created whenever this activity is created. Also only one instance will be available among all the tasks.
4) single instance : the activity will be created in a new task, and that task will contain only that activity. Also only 1 instance of that activity will be available for all the tasks.
Till now, I did not use any of the launch modes in my activities. So by default, i was using standard launch mode. I was wandering what are the various kinds of activities where other launch modes will be used. Do the Android applications (like search , map) have activities which uses other launch modes as well ?
Upvotes: 2
Views: 608
Reputation: 32261
Generally speaking there are just two common modes: Standard and Single Top, standard allows you to have multiple instances of the same activity, for example somebodys profile will be a great idea for standard lunch mode, as there could be multiple profiles in your app.
But if you are implementing a lobby activity, you probably want to set it as single top, as you don't want to launch new lobby activity each time you send someone back to the lobby.
And there are another two modes: Single task and Single Instance, both of them require that they will be the ROOT of the stack and the difference between them is that Single Instance also don't allow any other activities in the stack.
You will probably use Single Instance for some security app, for example processing credit card details.
And Single Task can be used for updating some important user information, so you want to make sure you always start clean and up to date.
Upvotes: 2
Reputation: 1061
There are some uses here:
http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode
I've used single top once for an activity that was called by two async tasks for Bluetooth and wifi that basically launched as soon as they received a response message from the server. Sometimes two messages would arrive and double launch the activity within 1s of eachother and that's how I found out about launch modes.
As far as the native android apps go, I'd say it's hard to tell what is going on under the hood for launch modes but I'd question if this piece of information would even matter. You know what they do now, so use em when it's applicable :D
Upvotes: 2