pedd Mylast
pedd Mylast

Reputation: 67

avoid android to clear my static fields

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

Answers (3)

Sam
Sam

Reputation: 972

SQLite is convenient and useful. Avoid to make a container as static, it's poor efficiency.

Here is an example.

sqlite example

I hope it's useful.

If you consists to use static fields, use bundle to store it instead.

It's an example about bundle

Upvotes: 0

Buda Gavril
Buda Gavril

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

blessanm86
blessanm86

Reputation: 31779

AFAIK you cannot really avoid these situations. There are many alternate methods like

  1. Subclass the 'Application' class and add your values there. But this can also get set to null when android needs more memory.

  2. 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

Related Questions