小编Fra*_*zzo的帖子

Android:如何更新我的应用程序时重置FirstRun SharedPreferences?

我的应用程序在第一次运行时将文件从res/raw复制到sdcard.我希望它在每次后续应用更新时更新这些文件.如何在每次应用更新时将firstrun首选项重置为true?

这是相关代码:

/**
     * get if this is the first run
     *
     * @return returns true, if this is the first run
     */
        public boolean getFirstRun() {
        return mPrefs.getBoolean("firstRun", true);
     }

     /**
     * store the first run
     */
     public void setRunned() {
        SharedPreferences.Editor edit = mPrefs.edit();
        edit.putBoolean("firstRun", false);
        edit.commit();
     }

     SharedPreferences mPrefs;

     /**
     * setting up preferences storage
     */
     public void firstRunPreferences() {
        Context mContext = this.getApplicationContext();
        mPrefs = mContext.getSharedPreferences("myAppPrefs", 0); //0 = mode private. only this app can read …
Run Code Online (Sandbox Code Playgroud)

android

12
推荐指数
2
解决办法
5158
查看次数

标签 统计

android ×1