Vlad Iancu
Vlad Iancu

Reputation: 487

Initiating "Clear data" for an app from settings in app code (Android)

I know this may seem as a silly question, but is it possible?

In cause you are wondering why am is asking this... I made an update to an app of mine that, if installed over the previous versions, it make it crash in a certain vital point, and it will only work if you go to settings and "Clear Data". I was wondering if i could use some code snippet to make this automatically for this version.

Upvotes: 0

Views: 582

Answers (2)

Blaze Tama
Blaze Tama

Reputation: 10948

You probably need to delete the SQLite file and SharedPreferences.

You can do some answers in this question :

How to programmatically clear application data

Upvotes: 0

dabluck
dabluck

Reputation: 1181

A better fix to your problem would be to figure out why it is crashing at this point and to address that. You can likely make use of the SqliteHelper#OnUpgrade method to accomplish this.

that being said. I assume that this would fix your problem:

 File dir = context.getFilesDir();
 FileUtils.cleanDirectory(dir); 

That gets the private file directory for your application and clears it, which is essentially what the clear data function will do.

Upvotes: 1

Related Questions