简体   繁体   English

将android活动状态恢复为开始状态

[英]Restoring the android activity state to the state from where it begun

I am making an application in which I want the application to come to a state in which it was, when was installed into the mobile, which includes deleting all the stored sharedpreference keys and sqllite data. 我正在制作一个应用程序,在该应用程序中,我希望该应用程序进入安装到移动设备时的状态,其中包括删除所有存储的sharedpreference键和sqllite数据。 Is it possible, if yes then how? 是否可以,如果可以,怎么办? Thank you. 谢谢。

You can try this! 你可以试试看!

   FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(classname.this);
                        SQLiteDatabase db = mDbHelper.getReadableDatabase();
                        db.execSQL("delete from " + table.TABLE_NAME);
                        db.close();
                        SharedPreferences.Editor editor = sharedpreferences.edit();
                        editor.clear().commit();  

An event occurred when you want to start your application as new perform the following operations. 当您想以新的身份启动应用程序时发生事件,请执行以下操作。

Flush out all sqlite data
Flush out all pref data

start your SplashActivity with 开始您的SplashActivity

Intent intent = new Intent(this, SplashActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent); 

it will clear all activity stack and you will access your App with starting phase. 它将清除所有活动堆栈,您将在开始阶段访问您的应用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM