How to clear user data of your application programmatically? Here I share you my solution how to do this.

You also can clear your user data by clicking “Clear Data” button in Settings–>Applications–>Manage Aplications–> YOUR APPLICATION
Application Info Android Dialog

To do it programmatically you need to remove user data from application dir.

Below you can download source code of sample Android project.

Pay attention in MyApplication class:

Download it from github
Categories: Android Development

22 Comments

Mark waugh · 21 November, 2011 at 06:40

Thanks for this informative post. I’m using Android and using “Clear Data” to clear user data. But programmatically option is new to me and I’ll try it on. 🙂

Remote Data Centre · 22 November, 2011 at 06:46

Oh this is sweet i know how to program a little bit. and this information will come in handy in the future.

Damin martin · 29 November, 2011 at 11:03

Cool buddy!! I’m following exactly same way you describe to clear my Android user data. It’s really good and thanks for informative info.

Gagan Singh · 6 December, 2011 at 09:28

I Was used this code in my personal code but data is not cleared properly some data is not cleared when i checked in settings->application->manage application->app_name.
Every time near about 4 kb data is remaining ,idon’t know why?
please help……………….

Igor · 21 December, 2011 at 19:41

Hi, Gagan Singh
Are your application store all data in /data/data/ dir?

I think it may happens if some of your app data stores in SD card.

zeus · 10 January, 2012 at 14:44

Thanks , I’ve been looking for this exactly .

It comes very useful when performing clean-ups on Android JUnit Test.

Thanks again 😀

Hoffi · 29 March, 2012 at 08:28

Hi Igor,

thank you for this very informative post. I was searching for a way to clear the app data programmatically and you give me the solution 😉

Jorge Pizarro · 3 June, 2012 at 00:10

is there a way to clear the data programatically, but leave out shared preferences untouched? thanks in advance

sreelal · 17 January, 2014 at 07:09

Hi,

is there any way to clear other applications app data or uninstall app silently ….i dont want clear my current app data ,need to clear other app data…

    Igor Khrupin · 8 May, 2014 at 16:03

    Hi sreelal,
    I think this is impossible to make clear data or remove other application without special permissions.
    I know about some special relations between application which signed with same certificate.

antony · 13 March, 2014 at 12:08

very nice forum
thanks.

chillsakoon · 28 May, 2014 at 09:47

Dear is there need any special permission in manifist file? for clear data, cache

Aleration · 7 July, 2014 at 11:57

Very Good! I need this source… Thank you very very much!

Thit Oo · 26 August, 2014 at 13:48

it was many useful for me .
Thank a lot

Gonzalo · 18 November, 2014 at 08:25

What should you put in the asterisks? (**********)

    Igor Khrupin · 18 November, 2014 at 14:06

    Nothing. I’ve updated post for better understanding

      Gonzalo · 19 November, 2014 at 01:04

      Yes!. thank you very much

Peter · 10 December, 2014 at 09:48

Thank you so much for this nice post. A question: Why must the class extend Application? An Explanation would be great!

harman · 20 January, 2017 at 10:07

how can we clear cache in api 23

mona · 22 June, 2017 at 14:38

Hi khrupin, your article is great that helps me 🙂 .
How to know the size of the app data before i clear them programatically?

Leave a Reply

Your email address will not be published. Required fields are marked *