My opinions:
Each one is best depends on the scenario. Let me explain.
Static Variable:
Static variable are common ways to give access to whole application context. If you want to maintain few datas which is not necessary to be maintained after the application exited, this is the best one.
Passing data through Intent:
This is not a kind of data storing. This is a kind of data sharing. I think this is the best way to pass data from activity to activity. But maintaining the keys for values in Constants is a good programming thing.
Shared Preferences:
Shared Preferences is nothing but a simple table which has two columns. (key, value).
advantages:
- Fast retrieval
- Easy to understand and program
cons:
- Maintaining Keys are difficult if we store a lot of values.
- User can clear this at any time.
Database:
When we have a lot of values to store with complex structure, we are left with only one great solution, ie. DB.
advantages
- We can maintain structure of data.
- Android has nice and simple APIs to handle sqlite operations.
cons
- Operation is little bit slow comparing to shared preferences.
- user can clear this at any time.
So we found the major problem is we can't maintain the persistence whatever storage we use. A simple and effective solution is to maintain data online and sync it with mobile db each time the application is started.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…