If you really have to use static / globals, put them in your own class that extends Application. Like this:
public classYourApplication extends Application {
protected Bar myBar;
public Bar getBar() { return myBar; }
public void setBar(Bar bar) { myBar = bar; }
...
}
Declare that you are using your own application class using the manifest.
<application
android:icon="@drawable/ic_launcher_noteit1"
android:label="@string/app_name"
android:theme="@style/App_Theme"
android:name="YourApplication"
android:debuggable="true">
Now you can access your application object from any activity using (YourApplication) getApplication (). Please note that this is not a recommended method. The recommended method is to use a singleton pattern. (answer from one of my answers to the question)
source
share