1

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
SunSunny
  • 25
  • 7

2 Answers2

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