简体   繁体   中英

Android clear application data

How do I clear my application data with the app closing by using ActivityManager

ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
boolean res = am.clearApplicationUserData();

I tried using the code above and the app quit without any warning

I want to be able to clear the data and then write new database on the flag and restart the app after writing the data to SharedPrefences

NOTE : am.clearApplicationUserData() works to clear the user data but I'm not getting back the flag to determine if the clear was successful or not.

Log : ActivityManager: Force finishing activity ActivityRecord{65dc437 u0 {package}/{package}.WelcomeActivity t794}

ActivityManager: Force finishing activity ActivityRecord{65dc437 u0 {package}/{package}WelcomeActivity t794 f}

ActivityManager: Duplicate finish request for ActivityRecord{65dc437 u0 {package}/c{package}WelcomeActivity t794 f}

ActivityManager: Force stopping {package} appid=10142 user=-1:clearApplicationUserData

ActivityManager: Killing 3343:{package}/u0a142 (adj 900): stop {package}

ActivityManager: cleanUpApplicationRecord -- 3343

clearApplicationUserData() is designed to work like that, once you call it, the app process will be killed without any warning. According to what you described, you only need to delete the database manually and recreate a new one instead of resetting the whole app data which doesn't answer your request efficiently.

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