I want to clear my application's data programmatically.
Application's data may contain anything like databases, shared preferences, Internal-External files or any other files created within the application.
I know we can clear data in the mobile device through:
Settings->Applications-> ManageApplications-> My_application->Clear
Data
But I need to do the above thing through an Android Program?
Best Answer
There's a new API introduced in API 19 (KitKat): ActivityManager.clearApplicationUserData().
I highly recommend using it in new applications:
If you don't want the hacky way you can also hide the button on the UI, so that functionality is just not available on old phones.
Knowledge of this method is mandatory for anyone using
android:manageSpaceActivity
.Whenever I use this, I do so from a
manageSpaceActivity
which hasandroid:process=":manager"
. There, I manually kill any other processes of my app. This allows me to let a UI stay running and let the user decide where to go next.