How to Clear User Data in your Android Application programmatically

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:

package com.hrupin.cleaner;


import android.util.Log;

public class MyApplication extends Application {
	private static MyApplication instance;

	public void onCreate() {
		instance = this;

	public static MyApplication getInstance() {
		return instance;

	public void clearApplicationData() {
		File cache = getCacheDir();
		File appDir = new File(cache.getParent());
		if (appDir.exists()) {
			String[] children = appDir.list();
			for (String s : children) {
				if (!s.equals("lib")) {
					deleteDir(new File(appDir, s));
					Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");

	public static boolean deleteDir(File dir) {
		if (dir != null && dir.isDirectory()) {
			String[] children = dir.list();
			for (int i = 0; i < children.length; i++) {
				boolean success = deleteDir(new File(dir, children[i]));
				if (!success) {
					return false;

		return dir.delete();

Download source code. Here you can download sample project.

14 thoughts on “How to Clear User Data in your Android Application programmatically

  1. 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. :)

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

  3. 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.

  4. 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……………….

  5. Thanks , I’ve been looking for this exactly .

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

    Thanks again :D

  6. 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 ;)

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

  8. 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…

    • 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.

Leave a Reply

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

8 − = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">