简体   繁体   中英

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. 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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