Sqlite Database deleted when I clear data from Application - android

I have created Sqlite database in app. when I clear data from settings->applications->manage applications the Sqlite db removed. any suggestions to keep sqlite database as it is.

When you press Clear Data from the Android application manager its supposed to remove everything related to the app such as preferences, databases, caches etc the only thing that gets left is the app so when you re-launch it behaves as if it was just installed.
If you want to allow the user to clear the data but keep the database then there should be an option in the menu that removes the shared preferences but doesn't do anything with the database.
Hope this helps.

Android's SQLite is intented for local app data storage. When you opt to wipe your app's data, this data is wiped (as expected).
If you want to persist DB data, look into external storage (eg. the late Parse.com, or MS's Azure). You'll be making network calls, your local data will still be wiped, and you'll need to have a way to link your app back up with the external data post-local-wipe (eg. logging in) but your external data will survive an app data clear.
The "linking up" part can be mitigated as well depending on your use case, eg. Google Play Games' data services is tied to your Google Play id and will resync after an app wipe.

Why would you want to keep the data when the user wants to clear everything.
It is not suggested you keep the db.
I would suggest you use the sd card to store images/text files with the adequate permission from the user.

Related

While clearing cache the data stored in local database gets erased. How to avoid this issue in Flutter-SQLite-Dart application?

I'm using Flutter-SQLite-Dart to develop a mobile application that has basic functionality just as Quiz application. I store questions and answers to my local database, when cache is cleared then the stored data gets erased. I need to save those data without getting lost. What methodology to use for achieving a solution for this issue?
For Android, you have two options in App info - clear data(clear storage) and clear cache.
By default, SQLite DB is saved in the internal app data directory, so when you clear the cache(app cache directory), all your DB data are still alive. But if you clear data(clear storage) you remove your DB + cache + other data.
If you want to keep DB after clear data(clear storage) or uninstalling the application, you have some options:
Back up user data with Auto Backup
Auto Backup for Apps automatically backs up a user's data from apps that target and run on Android 6.0 (API level 23) or higher. Android preserves app data by uploading it to the user's Google Drive—where it's protected by the user's Google account credentials. The amount of data is limited to 25MB per user of your app. There's no charge for storing backup data. Your app can customize the backup process
You can try to change the DB saved directory. For example, save it to Documents or so.
Use firebase_database
All those options have pros and cons...
And pay attention please, when the user will try to clear app data, Android will show an alert dialog with the next information:
All this app's data will be deleted permanently. This includes all files, settings, accounts, databases, etc.

Preserving SQLite db data on App Update/Reinstall Rollout Xamarin

I have Xamarin.Forms shared project that I am testing on Android phone currently.
The sqlite db is stored in System.Environment.SpecialFolder.Personal as of now.
I want to make sure that user input data stored in db is preserved:
1 upon each next upgrade I am planning for an app, as well as
2 In additional situation where user removes his app totally and makes a fresh install
(I guess these are two totally different situations, but I might be wrong)
I would like to know whether an update of an App via Google Play Store Update will overwrite db file too, therefore all data be lost? Or will the data be preserved?
What would be the option if a user wanted to preserve his/her data even after an app Uninstall/Reinstall?
In second case, I am considering manual/automatic backup of SpecialFolder.Personal db version in use and storing it as a separate file outside of the package using External_STORAGE permissions.
Then the user will be able to Import data from external db file copy into the one that comes in the package.
Also, how should the Import look like?
Can I simply replace the file with external one?
Any advice on this topic will be very appreciated.
An update from Google Play will not overwrite the db file
If a user uninstalls the application, he will want to delete everything related with the application. So my best solution is to have a synchronize method within your API so that, when the user installs again the application, it will fill the local DB with the requested data.

How to use database with React native?

I am building my first app with react native.
I am, for now, storing locally with AsyncStorage the user data.
This app is going to make users interact with each other, I am looking at realm.io but for my understanding all the mobile apps save the data locally then sync it to a database.
I am not sure if this is the way and I am doing correct. Basically what I want to do is :
Open the app, load the user data from AsyncStorage
Call the database (from a server) download other users data
Store user and users data in to the state of the app (I use redux)
Sync with the live database at each interaction.
Is this the correct way? For example if is a chat and I want to store the data for both users in to the database, how do I do?
So to recap, how do I store the app data for all users in a live database that is on a server?
What you're looking for is redux-persist https://github.com/rt2zz/redux-persist
What redux persist does is handle all the local storage things on its own any time it changes. So when you reopen the app everything that you want is there. You handle the database loading as you would normally and send it to your redux store and replace the old data.
Persist also has a black and white list for some of the things that you may or may not want to be saved. If you want to save everything in the store though it does it by default.
If you have important things that you want to be saved, you'll want to move it into the store if you have it in the state, because it does not save state.

Data save for an android app after it uninstall or force data clear from settings

I want to give the user some point when they first install the app (but I want it to device specific). It means if he uninstalls and re-installs he will not get that point again. I have found below methods:
Keep device previous data in shared preferences which will be deleted if I release an updates of the app
Store previous data in sql database but if user clears data from settings it will be lost
Create a file in SDcard store data, saving that file in a folder with .foldername and check the file value, problem is that the user can delete it
Every time the user opens the app it sends device id to server, server will check it is previously stored or not before giving point. Problem is that server maintenance should be avoided.
Other than these 3 methods is there any other method?
Can you suggest me any other way,
or can you please tell me if there is no other method which would be better for 3 and 4?
Variation of 4.
using Google's backup servers, however the user can delete the data through his system settings.

Persist Database across "Clear Data" in Android?

I am working on an android application which requires a database to store the value from the app.
My requirement is that I need the database not be cleared when the clear data option in the app is done.
Anyone please suggest me the location where the database can be stored so that is not deleted when clear data option is used.
I assume you mean the "Clear Data" from the Preferences->Apps menu.
I recommend you review your reasons for preventing this.
Hitting "Clear Data" would allow the user to reset the application as when newly installed, which really means recover from possible application errors you haven't thought about.
You can store the data into mysql database and use server php to get data from android
Try this link
Does storing on SD Card works for you?

Categories

Resources