Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clearApplicationUserData minimizes the app

I want to erase the data of my app programatically. I've found the method clearApplicationUserData. But when I run it, the app minimizes itself. That is, the app goes to background, like when it is pressed the home button. This is my code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE))
                        .clearApplicationUserData();
} else {
        // TODO
}

There is some way to erase data using this method without minimizing the app?

like image 357
androidevil Avatar asked Apr 15 '15 19:04

androidevil


1 Answers

Method ActivityManager.clearApplicationUserData() will erase all your app's data, and kill the app process directly without any warnings. I check the documentation and the source, it seems not like a bug but designed to work like that. I have some speculations as below:

  1. This method is designed for completely reset your application. Maybe you can provide your users a completely reset option.
  2. This method is designed for testing convinience (you can reset the app without reinstalling it).

If you want to implemet your own method to manage your app's data. This answer maybe helpful.

like image 66
zz-m Avatar answered Sep 19 '22 09:09

zz-m