简体   繁体   English

重新安装应用程序后,为什么数据没有被删除。 在模拟器上?

[英]Why is data not being wiped after I reinstalled app. on emulator?

I wrote some test code to learn how to use SharedPreferences. 我写了一些测试代码来学习如何使用SharedPreferences。 The app saves data fine, but when I ran the application again by pressing "run" on eclipse, the console window said it was uploading, installing, and starting the application. 该应用程序可以很好地保存数据,但是当我在eclipse上按“run”再次运行应用程序时,控制台窗口说它正在上传,安装和启动应用程序。 Since it said installing again, I was expecting the data stored with SharedPreferences to be deleted. 由于它说再次安装,我希望删除存储在SharedPreferences中的数据。 However, the old data was still displayed when i went into the activity. 但是,当我进入活动时,旧数据仍然显示。

My program runs like this: 我的程序运行如下:

  1. splash screen 闪屏
  2. list menu activity with 3 activity options 列出具有3个活动选项的菜单活动
  3. the target activity where i implemented the saving function 我实现保存功能的目标活动

Here is my code for that specific activity: 这是我的特定活动的代码:

public class StartingPoint extends Activity {
/** Called when the activity is first created. */

int counter;
Button add;
Button sub;
TextView display;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    counter=0;

    add= (Button) findViewById(R.id.bAdd);
    sub= (Button) findViewById(R.id.bSub);
    display= (TextView) findViewById(R.id.tvDisplay);

    add.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter++;
            display.setText(""+counter);
            display.setTextSize(counter);
        }
    });
    sub.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter--;
            display.setText(""+counter);
            display.setTextSize(counter);
        }
    });

}

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();

    SharedPreferences prefs = getPreferences(0); 
    int getfromfile = prefs.getInt("counter_store", 1);
    counter=getfromfile;
    display.setText(""+getfromfile);
    display.setTextSize(getfromfile);
}

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();

     SharedPreferences.Editor editor = getPreferences(0).edit();
     editor.putInt("counter_store", counter);
     editor.commit();
}
}

Since it said installing again, I was expecting the data stored with SharedPreferences to be deleted 由于它说再次安装,我希望删除存储在SharedPreferences中的数据

Re-running the application from Eclipse is akin to doing an upgrade on the app in production. 从Eclipse重新运行应用程序类似于在生产中对应用程序进行升级。 All data associated with the app is left intact. 与应用程序关联的所有数据都保持不变。

You can clear out the old data in the emulator by the same means as you would use on a phone, via the Settings application and its Applications screen. 您可以通过“设置”应用程序及其“应用程序”屏幕,以与在手机上使用相同的方式清除模拟器中的旧数据。

That's just how it works. 这就是它的工作原理。 It installs over the previous install. 它安装在以前的安装上。 If you want to remove all that data, you can uninstall first, or you can clear data from Manage Applications. 如果要删除所有数据,可以先卸载,也可以从“管理应用程序”中清除数据。

I guess because testing some functionality in an app that uses shared prefs would be impossible if it was wiped every time you made a minor change to the code and re-ran the app. 我想因为在每次对代码进行微小更改并重新运行应用程序时擦除使用共享首选项的应用程序中的某些功能是不可能的。 See CommonsWare answer if you want to clear the data. 如果要清除数据,请参阅CommonsWare答案。

The easiest/clean soln to wipe your app data is to uninstall it using adb . 擦除应用数据的最简单/最干净的解决方法是使用adb卸载它。 You will find adb in your sdk. 你会在你的sdk中找到adb -e option is for emulator. -e选项用于模拟器。 Use -d for device. 使用-d作为设备。

Command you can run is: 您可以运行的命令是:

>adb -e uninstall <app_package_name>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 清除应用数据模拟器后数据插入失败 - Data insertion failed after wiped out app data emulator 应用重新安装后正在播放 - App playing up after being reinstalled 在 Android 上卸载/重新安装应用程序后保留 SQFlite 数据的最佳方法? - Best way to keep SQFlite data after app is uninstalled/reinstalled on Android? 重新安装应用程序后,不会删除“分析当前用户” - The Parse current user is not deleted after app reinstalled 模拟器未运行应用。 甚至DDMS也没有显示模拟器 - Emulator not running app. Even DDMS not showing emulator 我需要Adobe AIR for Android加密的本地存储或应用程序存储数据,即使在卸载或更新应用程序后也可以保留。 - I need Adobe AIR For Android Encrypted Local Store or Application Storage data to persist even after uninstalling or updating the app. 即使关闭并重新打开 Android 应用程序,数据似乎仍会保存。 我不想这样 - Data seems to stay saved even after closing and re-opening Android app. I don't want it to Android - 我在哪里存储应用程序更新时未擦除但在卸载时被删除的应用程序特定数据? - Android - Where do I store app specific data that doesn't get wiped on app update but does get deleted on uninstall? Chrome 79 错误刚刚从我的 Cordova 应用程序中擦除了本地存储。 我的用户可以通过什么方式恢复? - Chrome 79 bug just wiped Local Storage from my Cordova app. Any way my users can restore? 每次调试/部署时都会擦除应用程序数据吗? android Eclipse - Is app data wiped every time debug/deploy? android Eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM