I understand that there is no Application Level Scope available to be able to define shared logic/data, and that each activity is essentially a stand alone application tied together by the manifest...
BUT I have a group of user access permissions that I am getting via a web service call and do not want to make this call in every activities onCreate()
.
I am using SharedPreferences
in the application, but since the permissions are not intended to be editable by the user, the flat file exposure on android devices feels like an insecure way to handle this.
I do need to re-request this info if the application is restarted, so I believe the least expensive would be to store it in a variable.
I am aware of IntentExtras but we are talking about a Settings "Object", not a primitive type.
right way to handle this situation?
You can actually create an "Application" class that can be used to essentially create Application wide settings.
Just create a new class and extend Application, then set any class members and appropriate getter/setter methods and you can access them throughout your application.
You then need to update your manifest as follows:
<application android:icon="@drawable/logo"
android:label="@string/app_name"
android:name=".application.CustomApplication">
Then in any activity you can access it as follows:
CustomApplication app = ((CustomApplication)getApplication());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With