I am making an android application in which I update SQLite database. I was wondering if I can track the number of times the application was opened.
Asked
Active
Viewed 1,163 times
1
-
2How about using `SharedPereference` in `onCreate`? – MysticMagicϡ Jan 07 '14 at 05:34
-
Make SharedPref variable and increase every time on onCreate method. – Sagar Maiyad Jan 07 '14 at 05:40
-
You can use a conbination of sqlite and sharedPref.. so when you update the db.. store the open_app_counter in sharedPref.. and when finish update retrieve it and put it again in db_sqlite. – Pablo Pantaleon Jan 07 '14 at 06:16
2 Answers
4
You can do it by following approach.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences prefs = this.getSharedPreferences("pref_name", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
int count = prefs.getInt("counter", 0);
count+=1;
editor.putInt("counter", count);
editor.commit();
Log.d("TAG","Counter : "+count);
}

Chintan Rathod
- 25,864
- 13
- 83
- 93
-
brother i need u r help in this http://stackoverflow.com/questions/20088247/navigation-drawer-with-backword-compatibility-android/20088711#20088711 again please help me in this – Developer Jan 08 '14 at 06:18
2
The the way you are going is correct. procedure just update the counter to the sqlite and access it from there.
SharedPereference is also possible but sqlite is better.
follow this URL for reasons: http://codeblow.com/questions/benefits-and-drawbacks-of-sqlite-and-shared-preferences/

Balu
- 1,069
- 2
- 10
- 24