increment Count in SharedPreferences - Android Android OS

Android examples for Android OS:SharedPreferences

Description

increment Count in SharedPreferences

Demo Code


//package com.java2s;

import android.content.Context;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Main {
    private static final String REVIEW_PREFS = "Review_pref_data";
    private static final String KEY_COUNT = "count";

    public static void incrementCount(Context context) {

        SharedPreferences sharedPreferences = context.getSharedPreferences(
                REVIEW_PREFS, Context.MODE_PRIVATE);
        Editor edit = sharedPreferences.edit();
        edit.putInt(KEY_COUNT, sharedPreferences.getInt(KEY_COUNT, 0) + 1);
        edit.commit();//from ww  w  .ja  v a  2s  .co  m

    }
}

Related Tutorials