First create a class called MasterActivity that extends the Activity and defines your global object.
public class MasterActivity extends Activity { public Object mObject; }
Then you need to expand your main activity class with MasterActivity, for example:
// your main activity public class MainActivity extends MasterActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // you can now use mObject in your main class mObject.yourmethod(); } }
Thus, you can use your object in all your actions by simply expanding MasterActivity instead of Activity.
source share