mardi 5 mai 2015

How to reset data on application update

I want to make a dialog box that disappears after application is launched for two times after it's updated (patch notes). It's done, but after I update/reinstall my app, old information is stored so my dialog box doesn't pop up. How can I refresh my launch_count?

public class MainDialogBox {

private final static int LAUNCHES_UNTIL_PROMPT = 2;

public static void maindialog(Context mContext) {
    SharedPreferences prefs = mContext.getSharedPreferences("maindialogbox", 0);
    SharedPreferences.Editor editor = prefs.edit();

    long launch_count = prefs.getLong("launch_count", 0) + 1;
    editor.putLong("launch_count", launch_count);

    if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
        return;
    }
    else showMainDialog(mContext, editor);

    editor.commit();
}

public static void showMainDialog(final Context mContext, final SharedPreferences.Editor editor) {
    final Dialog d = new Dialog(mContext);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setContentView(R.layout.activity_main_dialog_box);
    d.show();
}

}

Aucun commentaire:

Enregistrer un commentaire