9

I am using database to store some data. But when user go to Apps Settings and press the 'clear data' button in the app settings, data in databases gets deleted how can avoid this. Can I make 'clear data' BUTTON foR my app in Apps settings as not enabled or any other suggestions....

Sharanabasu Angadi
  • 4,304
  • 8
  • 43
  • 67
  • You may like to see this http://stackoverflow.com/questions/6531173/how-to-disable-the-clear-data-button-in-application-info-of-manage-appliaction – MRX Nov 04 '13 at 21:52
  • Answer here - http://stackoverflow.com/questions/6531173/how-to-disable-the-clear-data-button-in-application-info-of-manage-appliaction – Shirish Herwade Apr 21 '15 at 16:12

5 Answers5

4

Add android:manageSpaceActivity=".ActivityOfMyChoice" to the application tag of your Manifest like:

<application android:label="MyApp" android:icon="@drawable/icon" android:manageSpaceActivity=".ActivityOfMyChoice" >

Then instead of "Clear Data", there is a button for "Manage Space" which launches ActivityOfMyChoice

ActivityOfMyChoice.java

public class ActivityOfMyChoice extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    finish();
}

So when we click the Mange activity it finish the Activity.

Renjith Krishnan
  • 2,446
  • 5
  • 29
  • 53
3

There is no direct way to avoid any app data being cleared from what I know.

However, you could store your data on the external storage (SD card) in some file and at every app launch check if that file is there and merge it's contents into the database. This will of course not work if the user manually deletes your backup file from the SD, inserts another SD, removes the SD or connects the device as a mounted drive to the computer and then launches the app.

iseeall
  • 3,381
  • 9
  • 34
  • 43
3

Android won't ask whether your App like's its data to be deleted or not. It's a system functionality provided to user. User has power to totally uninstall the App.

So, create/open the database file at another location.

Data durability:

  1. App cache dir : deleted when internal memory is low.
  2. App data dir : deleted when user clears app data , app is uninstalled.
  3. External storage : user can delete anytime, user may also remove the storage.
  4. Backup manager : new versions of android offer Apps to backup data on cloud via BackupManager.
  5. Remote server : Stays in server until deleted.
S.D.
  • 29,290
  • 3
  • 79
  • 130
1

I think there's a way but haven't tried it yet. You can store your DB file in asset folder, check if it available, otherwise just do like this https://stackoverflow.com/a/9109728/265167 (pay attention on DataBaseHelper class). But do this way, you'll lose all "update data".

Community
  • 1
  • 1
Vinh.TV
  • 299
  • 3
  • 17
0

Finally I found some solution, If you make application system administrator then its not possible to clear data and uninstall app

Sharanabasu Angadi
  • 4,304
  • 8
  • 43
  • 67
  • 1
    How to make application system administrator? what is the setting want to do programatically? – Piraba Nov 24 '14 at 10:45