Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid deleting the data from database on clicking 'clear data' button in the app settings on android device

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

like image 213
Sharanabasu Angadi Avatar asked Mar 04 '13 10:03

Sharanabasu Angadi


4 Answers

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.

like image 166
Renjith Krishnan Avatar answered Nov 03 '22 15:11

Renjith Krishnan


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.

like image 23
iseeall Avatar answered Nov 03 '22 15:11

iseeall


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.
like image 45
S.D. Avatar answered Nov 03 '22 13:11

S.D.


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

like image 41
Vinh.TV Avatar answered Nov 03 '22 14:11

Vinh.TV