PhatHV
PhatHV

Reputation: 8141

Should i use static variables/methods or sending its values in a bundle?

I have a main Activity and some static variables (got values in onCreate() method).

I also have 6 other Activities and 1 Broadcast Receiver use this static variables. And they may be changed their values in a specify Activity or Broadcast Receiver.

Should i use static variables/methods or sending its values in a bundle? Which is better optimized?

Sorry for my English.

Upvotes: 0

Views: 372

Answers (2)

zrgiu
zrgiu

Reputation: 6322

Static variables can (and will be, a lot of the times) reset when the user sends your app into the background, because the system will serialize everything that it can keep track of to the disk, to keep for later use and save RAM. If you send your values in bundles though, all your data will be successfully saved and restored later when it's actually needed.

Upvotes: 3

slayton
slayton

Reputation: 20319

It sounds like you should be using the SharedPreferences

Upvotes: 2

Related Questions