2

Is it possible to wipe all application data from an activity that you create? Lets say onResume do something to clear the data that are probably stored.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
dothedos
  • 169
  • 5
  • 20

3 Answers3

2

You can manually delete all cached files from your app cache directory. You can get cache dir with:

context.getCacheDir();

Also, look at this - https://stackoverflow.com/a/3986001/492292

Community
  • 1
  • 1
Dmitry Stropalov
  • 790
  • 6
  • 14
  • 1
    Note that this works only for internal memory not on the sd card. – rekire Dec 07 '11 at 15:15
  • Yes, but app can put data anywhere on sd card, so there is no common way to clear it. – Dmitry Stropalov Dec 07 '11 at 15:23
  • That is true, but I want to inform dothedos. – rekire Dec 07 '11 at 15:25
  • Well as i am a noob to android development i see that no cache data are stored, no data are stored to my sd card as i debug in emulator, bit i see to my settings that some data are stored,sharedprefs, but i am not sure that all of them are just sharedprefs. Anyway i want to clear them all! – dothedos Dec 07 '11 at 15:31
  • Shared preferences stored in app cache dir too (shared_prefs dir), but it can be cleared with clear() method of SharedPreferences.Editor - http://developer.android.com/reference/android/content/SharedPreferences.Editor.html#clear() – Dmitry Stropalov Dec 07 '11 at 15:45
2

Accessing files on external storage

If you're using API Level 8 or greater, use getExternalFilesDir() to open a File that represents the external storage directory where you should save your files. This method takes a type parameter that specifies the type of subdirectory you want, such as DIRECTORY_MUSIC and DIRECTORY_RINGTONES (pass null to receive the root of your application's file directory). This method will create the appropriate directory if necessary. By specifying the type of directory, you ensure that the Android's media scanner will properly categorize your files in the system (for example, ringtones are identified as ringtones and not music). If the user uninstalls your application, this directory and all its contents will be deleted.

If you're using API Level 7 or lower, use getExternalStorageDirectory(), to open a File representing the root of the external storage. You should then write your data in the following directory:

/Android/data//files/ The is your Java-style package name, such as "com.example.android.app". If the user's device is running API Level 8 or greater and they uninstall your application, this directory and all its contents will be deleted.

Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
0

Using getFilesDir() you can get your applications default internal storage location. This is where one normally stores application specific data.

withoutclass
  • 564
  • 8
  • 16