How can I create global variable keep remain values around the life cycle of the application regardless which activity running.
Android global variable
androidglobal-variables
Related Topic
- Android – How to declare global variables in Android
- Android – Fling gesture detection on grid layout
- Android – How to close/hide the Android soft keyboard programmatically
- Android – Is quitting an application frowned upon
- Android – unique Android device ID
- Java – Proper use cases for Android UserManager.isUserAGoat()
- Sql – What data-type should I use to store monetary values
Best Answer
You can extend the base
android.app.Application
class and add member variables like so:In your android manifest you must declare the class implementing android.app.Application (add the
android:name=".MyApplication"
attribute to the existing application tag):Then in your activities you can get and set the variable like so: