Erik Z
Erik Z

Reputation: 4780

How long does the application object live?

In an Android app, how long does the application object live? If I have an application and all activities and services is closed and destroyed - does the application object still lives?

Upvotes: 2

Views: 546

Answers (3)

Sush
Sush

Reputation: 3874

Application alive until its any one component is alive. Now as per priority service has least priority in getting destroyed. Rest of the components will get destroyed as the device run out of memory.But android keep the reference of application for future launch even after service is killed.

Upvotes: 0

Ankit
Ankit

Reputation: 256

Yes, Like in Android there is no completely closing/exit of application. System will keep its object for future reference to reduce its lunching time and all. But when system requires to free some run time memory it will destroy as per its defined rule. Check this link

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007359

In an Android app, how long does the application object live?

It is created after any ContentProviders when your process is started, and it remains around until your process is terminated.

If I have an application and all activities and services is closed and destroyed - does the application object still lives?

It will "live" as long as your process lives. That may be anywhere from milliseconds to days, depending on what else is going on with the device. Hence, only use a custom Application object (or, better yet, ordinary Java singletons) for caching. Any data that needs to survive process termination should be stored somewhere persistent.

Upvotes: 4

Related Questions