1.

Explain different launch modes in Android.

Answer»

The different launch modes in Android are given below:

STANDARD:

  • This launch mode generates an activity’s NEW instance in the task from which it originated.
  • It is possible to create SEVERAL instances for the same activity.
  • For Example, suppose our current stack is A -> B -> C. Now, if we launch activity B again with the “standard” launch mode, then the new stack will be A -> B -> C -> B.

SingleTop:

  • This launch mode is similar to the Standard launch mode except if there exists an activity’s previous instance on the TOP of the stack, then a new instance will not be created.
  • But the intent will be sent to the activity’s existing instance.
  • For example, suppose our current stack is A -> B -> C. Now, if we launch the activity B again with “singleTop” launch mode,then the new stack will be A -> B -> C -> B.
  • Consider another example, where the current stack is A -> B -> C. Now, if we launch activity C again with the “singleTop” launch mode, then the stack will remain the same i.e., A -> B -> C. The intent will be passed to the onNewIntent() method.

SingleTask:

  • This launch mode will create a new task and push a new instance to the task as the root.
  • For example, suppose our current stack is A -> B -> C -> D. Now, if we launch activity B again with the “singleTask” launch mode, then the new stack will be A -> B. Here, a callback has been received on the old instance and C and D activities are destroyed.

SingleInstance:

  • This launch mode is similar to the SingleTask launch mode. But the system doesn’t support launching any new activities in the same task.
  • In a situation where the new activity is launched, it is launched in a separate task.
  • For example, Suppose our current stack is A -> B -> C. Now, if we launch the activity D with the “singleInstance” launch mode, then there will be two stacks:
    • A -> B -> C
    • D, If you CALL activity E, then it will be added to the first stack.
    • A -> B -> C -> E
    • D

Again if you Call the activity D, then it will call the same activity from the 2nd stack and pass the intent to onNewIntent().



Discussion

No Comment Found