Reputation: 429
In an Android app is it safe to keep a reference to the application context returned from Context.getApplicationContext()
throughout the lifetime of the app?
Context ac = context.getApplicationContext();
// keep the ac reference throughout the app lifetime
Upvotes: 6
Views: 1085
Reputation: 1212
Yes. The application context wont change until the app gets killed by the system.And when the app gets killed, your variables get cleared. On the other hand, its unsafe to persist activity context.
Upvotes: 6