I am using database
to store some data
. But when user go to Apps Setting
s 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....
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.
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.
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:
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With