Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Android Context mutable?

Tags:

android

I want to store the application context in a static member, like this, so I can access it, the shared preferences, resources etc. everywhere.

My question is whether the context can change itself during the application lifetime, so the stored context won't work in a proper way and I can't access shared preferences etc.

Or is the context immutable, so I can use it without any doubt?

Thanks for you answers!

like image 952
JaMic Avatar asked Dec 17 '25 01:12

JaMic


2 Answers

Application context stays unaltered during application lifetime.

like image 77
Marcin Orlowski Avatar answered Dec 19 '25 18:12

Marcin Orlowski


Context is immutable during all work of app. And you can use it in static way to get resources, shared preferences, etc.

like image 23
Artyom Kiriliyk Avatar answered Dec 19 '25 20:12

Artyom Kiriliyk