Kostadin
Kostadin

Reputation: 2549

Start another application activity and keep it alive

I have 2 applications A and B. Both have only one activity. Application A starts application B. When I close activity in B - I return to A. How to keep application B in memory? If I close activity in B with finish() - B remains im memory. Does this means that next time Android will use it or start another instance?

UPDATE

If application B have single task or single activity set in manifest? Or may be behaviour of B will depend on intent from A?

Upvotes: 1

Views: 519

Answers (1)

David Wasser
David Wasser

Reputation: 95568

When you ask "How to keep application B in memory?", what exactly do you mean?

If you are really talking about 2 separate applications, then Android will start each application in a separate process. Each process has its own Virtual Machine. If an activity in application A starts an activity in application B then you will have 2 running processes. Once the activity in B calls finish(), it is done. At some time later Android will call onDestroy() on the activity in B and then at some time later Android will kill the process that B is running in. Android will kill off the process when it needs the memory, or whenever it decides that it wants to, based on whatever internal criteria it uses for killing processes.

Once the user has returned to application A from application B, if the user again starts an activity in application B Android will create a new instance of that activity in the process where application B is running. If the process has already been killed by Android, then Android will create a new process for application B and then create a new instance of the activity within that process.

Once an activity has called finish() it will never be reused. It is done. It is dead. It is ready for destruction and garbage collection. It makes no difference what launchMode you set for the activity or what flags are set in the Intent.

I hope this answers your question(s).

Upvotes: 1

Related Questions