Reputation: 67
it seem that android SDK autmattically clear static fileds as it needs memory , how can I avoid specefic static filed to be cleared by android device ...
public static ArrayList<PackageInfo> applications = new ArrayList<PackageInfo>();
thanks.
Upvotes: 0
Views: 249
Reputation: 972
SQLite is convenient and useful. Avoid to make a container as static, it's poor efficiency.
Here is an example.
I hope it's useful.
If you consists to use static fields, use bundle to store it instead.
Upvotes: 0
Reputation: 21657
you may save your data in shared preferences or in an sqlite database or you can try to use references (strong recomanded)
Upvotes: 0
Reputation: 31779
AFAIK you cannot really avoid these situations. There are many alternate methods like
Subclass the 'Application' class and add your values there. But this can also get set to null when android needs more memory.
The better solution would be to to use the sqlite storage. You can be sure that your data will not be cleared.
I would go with the option 2.
Upvotes: 4