I'm using realm(also tried sharepreference) to save some information.But When I cleared app's data,All information has removed.
I have one question.How I can save some information to my device,witch always 'll be in storage? (if i cleared data or uninstalled my app)
Yes, clearing local data delete shared preferences and data in the local SQL Lite database as well. However you can make a folder for your app in local SD card or in phone's internal storage. These folders will not be deleted even if your app uninstalled. In these folders you can store your data in some sort of a format, it maybe in plain text or it maybe some encrypted files. It's your call.. hope this helps
Related
I have developed an app that is to save daily income and outcome. Those income and outcome will be update every time. If my phone is break down, my app's data will be lost? How should I do to save income and output record.
If you have a external storage on your phone, such as an SD card, you could save your data to a SQLite database located here, so you're not losing you data even if you do a factory reset. Most devices won't never delete your SD Card data during a factory reset, some other may ask you if you want to.
Any information android would by default keep in the data folder, except non critical stuff (remembering user's login, personal settings...) should be saved in the external directory.
To write to the external storage, you must request the WRITE_EXTERNAL_STORAGE permission in your Manifest, and while creating the database, call an overloaded method that allows you to specify its location.
Upload (Post by using php) details to website database by using json
api.
Or save data (encrypted text or other file) in memory card.
Or use sqlite technology.
I am working on logs inside android, I thought two ways for storing logs, and one is on external directory as a text file or a log file while other is to store in database. I found database method more useful in my case. My question is if I UN-install and reinstall the app will the database will be affected? In case of yes what should I do? I cannot place the logs online. How to take the backup or safe that database so it won’t be affected in case of UN- installation.
My question is if I uninstall and reinstall the app will the database will be affected?
Yes, your database will by default be stored in the application's data directory, which is deleted along with your application on uninstallation.
You can instead write a file of a filetype of your choosing (whether that's a simple text file, or a database file) to the external storage. You can obtain the directory path using:
Environment.getExternalStoragePublicDirectory(type) for obtaining a directory path of files of a specific type, such as images or videos;
Environment.getExternalStorageDirectory() for obtaining the primary external storage directory, under which you could create a new path.
I would nevertheless discourage you from doing this, because it would require your users to manually dispose of any files after uninstalling your application. Perhaps you should reconsider the justification of choosing for this solution.
If you uninstall the app, then the database (and all other data stored in the apps private storage for that matter) will be gone.
You could store your logs in the public external storage, but this will expose your logs to other applications as well as the user.
One possible approach could be to use application private storage for your 'live' logs, and make periodic backups to the public storage. In case of a new installation, you can check your designated backup location and attempt to restore previous logs from the backup.
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.
I have the problem to store the downloaded data in my android device Now I store the data on my sdcard, but this is not much prevent from the user. I need to store the data securely from the user. How can I do that?
there is no way you can prevent the user from accessing your data. The max you can do is :
Make the folders you create as hidden ( prefix the folder names with a . )
remove the extension of the files you create, if possible. In most cases you can still access them & your files dont show up in other apps (like music players, Image viewers).
For storing senstive data or some downloaded dat in the application , just use internal Storage. ie "data/data/{App package name}/{direcdtory name}". if you store data inside the internal storage, only your application can access the data not the user nor other application.
My android app saves user information as serialized objects in a ".ser" file that's saved to internal storage.
The data can be stored and retrieved and written just fine but whenever the user installs an update to the app, all the data is erased.
I assume the file is deleted upon installation of an update.
My question is: how do I save data to internal storage without it getting deleted when users install updates?
Do I have to use a different method, like SharedPreferences or SQLite?
or can my FileOutputStream save persistently through updates?
If you're worried about it getting deleted on internal memory, why not write to the ext?
Hello Boron I've been using SharedPreferences for the purpose you are explaining. I don't think SQLite would be preferable because you might want to save the images and large information like Bio of the user.
I store all my user data in shared preference and I am almost positive that the data persists even on updating the application. This should solve your problem.
When you have to store the images I would suggest you to convert the image to base 64 or some string and store in SharedPreferences this reduces the chances of deleting of the image from mobile by user accidentally.
Happy Coding