Question: I have an application which has some static variables.
These variables are stored in an independent Class named DataContext.
These variables are initialized from raw files at the application start (a method named DataContext.initConstant() is called in the onCreate() of MyApplication which extends Application).

(EDIT : the initConstant method use an AsyncTask to load this data from files).

When my application comes to the background for a certain time or when my application used to much memory, these static variables become null.

1. How can it be prevented?
2. If not what should I do with my static variables?

I have other data which are stored in static variables to be used across different activities, but I clear them or pass them to null in the `onLowMemory()` of MyApplication.
3. What is the best way to keep some data accessible between activities if these data are too big to be serialized in an Intent, a database can't be used (for whatever reason), and can't be stored in files through serialization either?

Answer: 
I assume this is a data cache problem.

Storing data in static class is not guaranteed to work when user swap apps often. Android system will reclaim any background activity when memory is low. Static class is definitely among this category.

The proper way to do it is to use [sharedPreference](http://developer.android.com/guide/topics/data/data-storage.html#pref) to persist cache data.

You can create your own getter and setter of the data you want and wrap it around sharedPreference object. When you access using getter, you should always check if the value is empty or expired. You can store an `update_time` when using setter.

For activity specific data, you can just use `getPreference(permission)`, if you want to share data across activities and other applications components, you can use `getSharedPreference(name, permission)`.

Normally, the permission will be MODE\_PRIVATE such that the data can only be accessed within your application. 

You should group data and store in difference sharedPreference object. This is good practice because when you want to invalidate that group of data, it is just a matter of one liner.

`editor.clear(); editor.commit()`

If you want to cache complex object, you should serialize it. I prefer JSON format. So you need some conversion mechanism in place. To do this, I will create my data object class extending JSONable class. JSONable class will have `toJSON()` method and `readFromJSON()`. This is convenient when restore and serialize data.
Instead of using the static variable u can use the shared preference for storing the value.

Note: for shared preference also you should not give heavy load.

I have solved this problem by having the super class with getter and setter function for storing and retrieving shared preference variable.

All class in my application extended the super class instead of activity.