Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { private static final String REVIEW_PREFS = "Review_pref_data"; private static final String KEY_REVIEW_DONE = "ReviewDone"; private static final String KEY_COUNT = "count"; public static boolean isReviewNeeded(Context ctx, int count, boolean incrementCount) { if (incrementCount && getCount(ctx) <= count + 1) { incrementCount(ctx); } if (isReviewDone(ctx) || !isConnectionAvailable(ctx) || getCount(ctx) < count) { return false; } return true; } public static int getCount(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences(REVIEW_PREFS, Context.MODE_PRIVATE); return sharedPreferences.getInt(KEY_COUNT, 0); } 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(); } public static boolean isReviewDone(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences(REVIEW_PREFS, Context.MODE_PRIVATE); return sharedPreferences.getBoolean(KEY_REVIEW_DONE, false); } private static boolean isConnectionAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } return false; } }