Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final String MyPREFERENCES = "MyPrefs" ;
- public static final String counterKey = "counterKey";
- SharedPreferences sharedpreferences;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //doing basic stuff of set layout and all here...
- //Initialize sharedpreferences here
- sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
- //call to increment counter here
- updateAppOpenCounter();
- //do remaining stuff here....
- }
- private void updateAppOpenCounter() {
- SharedPreferences.Editor editor = sharedpreferences.edit();
- editor.putInt(counterKey, getAppOpenedCount() + 1);
- editor.commit();
- }
- private int getAppOpenedCount() {
- sharedpreferences.getInt(counterKey, 0); //Kept 0 as default opened count if not set to shared yet.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement