Is it possible to create a variable in the starting activity (eg : Book class in Activity 1)
and have it available anywhere in the application (eg Book class in Activity 3 , 4 &5) without actually passing it.
I am asking because my xml handler creates a series of objects be it also updates the xml file after any change is made to the object.
You can create a static variable. As long as it’s declared with appropriate access (e.g.,
public) it will be directly available to any activity in the same process. (This will be the default; you need to do extra work to get an activity into a separate process.)It’s common to separate out such global variables into a separate class.
However, be aware that if your app is pushed into the background, there’s a chance that the process will be killed off and re-created. In that case, any data stored in static variables will be lost. Alternatives include using SharedPreferences, a data base, or a ContentProvider.