Jakob Bjerre Jensen
Jakob Bjerre Jensen

Reputation: 429

Is it safe to keep a reference to Android application context?

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

Answers (1)

Kiran Kumar
Kiran Kumar

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

Related Questions