I'm using React Native to build an android/ios app. I'm using expo-secure-store with the bare React Native app and expo-secure-store saves data in SharedPreferences as encrypted on Android.
After I was updating my app, I received many reports from users that their data in SharedPreferences are reset and lost. On iOS, I didn't get such reports.
Is there any condition to reset data saved in SharedPreferences except the removal of the app?
As far as I know, data saved on SharedPreferences remains during its update. Is it wrong? I could not find any answer from the documentation. Please let me know about it.
The SharedPreferences data survives updates, but if the new app version expects different keys or value types, the new version of the app may not be able to read the information correctly.
Apart from app uninstall, the user can delete the application data which will also remove the SharedPreferences data.
Related
Im trying to make a currency converter, and so I get the values from the internet and if the user turns the internet off the values are being saved in the shared preferences so that the user can go on using the converter without the internet.
The problem is first installation. How can I make it work in the way that shared preferences from the last usage install themselves within the application. Let me give you an example:
1) I get the current rates, save them using shared preferences.
2) I uninstall my app
3) Install my app again
4) Rates in my shared preferences are the ones from point 1.
So your problem is that your Prefs are remain after you deleted and installed your application again? Looks like you should add
android:allowBackup="false"
in your Manifest in the <application> block, because I guess your Prefs are stored in your Google Drive :)
From official documentation:
Whether to allow the application to participate in the backup and restore infrastructure. If this attribute is set to false, no backup or restore of the application will ever be performed, even by a full-system backup that would otherwise cause all application data to be saved via adb. The default value of this attribute is true.
I am developing a Restful Webservice using Eclipse and an android application. User logs in using its username and password on the android application which is checked against the database at the server side(using this web service).
Now, I want to maintain a session for which the user will remain logged in, that is, the user does not have to log in again and again whenever he re-opens the application.
How to do it? I searched on net but I could not find an accurate solution. Kindly help with the appropriate solution. Ask if more information is required.
use Shared Preferences to save session data .
there are good tutorials :
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
http://androidexample.com/Android_Session_Management_Using_SharedPreferences_-_Android_Example/index.php?view=article_discription&aid=127
This can be done in two ways. One is storing them in a global variables and second is storing the data in shared preferences. The problem with storing data in global variable is data will be lost once user closes the application, but storing the data in shared preferences will be persistent even though user closes the application. Here is the complete example:
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
I'm developing a group of complex Android applications that need to share common state and configuration settings.
For example, see this picture explaining my scenario:
I want that APP 1, APP 2 and APP 3 be able to access (read/write) data to the common storage area. Additionally, I need uninstall protection i.e. I don't want the data to be removed when the user uninstalls any of the apps.
I've already read about SQLite databases, ContentProviders and writing on Internal and External storage, but each of the above mentioned methods have disadvantages as listed below:
SQLite database: DB is deleted on app uninstall and is private to each app
ContentProvider: The data is removed when the app with the ContentProvider is removed
Internal storage: Is private to each app and data is deleted on app uninstall (http://developer.android.com/training/basics/data-storage/files.html#InternalVsExternalStorage)
External storage: Is unreliable (user may remove SD card)
Store on server: Not possible, user may not have reliable internet connection
EDIT:
I don't want any dependencies on Google Play Services because I will be distributing the apps via Play Store and as 3rd party downloads.
Please help me out.
Google Drive sort of does this for you. You basically get granted permission to a local filesystem that is backed by a remote one. On most phones this is getting preinstalled so the uninstall issue you are worried about is less of an issue.
You could create a folder for your apps that you can then read/write.
https://developers.google.com/drive/android/
You can use the shared preferences object to read and write preferences data from a file. Most important is to use MODE_MULTI_PROCESS. The bit MODE_MULTI_PROCESS is used if multiple processes are mutating the same SharedPreferences file.
Use the following code:
SharedPreferences shPrefernces = context.getSharedPreferences("filename", MODE_MULTI_PROCESS);
String s1 = shPrefernces.getString("keytosearch1", "");
String pass = shPrefernces.getString("keytosearch2", "");
I agree that Shared Preferences with world_readable will not sufficient for you or sharing across internet is not possible, but still you can do one thing.
Using Broadcast receivers and Custom Broadcasts.
with redundant common data across all apps with shared preferences.
Who updates the data will send a broadcast to system.
All the apps implement broadcast receiver. when ever a new broadcast received they update the data in shared preferences.
App A -> sends broadcast when data is updated.
If App B is installed already App B also receives broadcast and save the data from that intent.
if App B updates new data.
APP B -> sends broadcast for the common data
Other Apps will update data.
Only common data will be lost when all apps are removed. If at least one app is installed data persists.
Preference data will always be stored inside each applications own context. Use sharedUserId and have a new preference file created in all the apps. On opening each app, the app has to check for the preference value from all other applications context and should write into its preference based on last updated time value available in the preference to find the latest updated one.
Whenever any app is opened, the latest data will be stored in its local. if any of the app is installed or uninstalled, this should work fine.
I already know how to persist normal data throughout Android activities, but I'm wondering if the same methods are safe to use for Android purchase data.
I'm making a free app that uses in-app purchases to unlock all the content. This is something that I'm currently checking in the splash screen activity in order to customize the UI, however I would also need this information throughout the app.
Is it best to query in each activity, or is a Shared Pref safe enough?
As a note, I'm using v3 of Android' billing library.
Thanks
Shared Preferences are OK for this. Your data is sandboxed the same as if it were a database. (Security-wise, both are just as safe)
You will need to query either the database, or SharedPreferences to get this data in your Activity regardless. Doesn't really matter from which data store you retrieve it.
You don't have to worry about users changing your data (somehow changing their local status to 'paid') as they aren't able to change your SharedPrefs (or database values) - since they don't have access to these secure data stores.
I built an application that will download and install an APK from a WebService using the technique described here:
Install Application programmatically on Android
During this installation, the Webservice sends a 'flag' that indicates if the SQLite database from the application that is being updated should be deleted or not during it´s first run.
Is there any way to set a "Global Preference" that could be read (if the flag is true, the database should be deleted) and cleared (it should be set to false after deletion to avoid deleting the database all times that app is started) during the first usage of the updated app, without saving it to the SDCard?
I know how to read the preferences from the app that is being updated but, I did´t realize how to modify these preferences from another app.
Thanks a lot.
SharedPreferences are unique to each App/APK - no way to share them that I'm aware of and no 'Global' equivalent.
If you want to share data, the solution is usually some sort of ContentProvider, but that relies on both apps running at the same time.
If you only want to hand-over a token or state, I'd suggest writing a file onto the SDCARD is probably the simplest option?
Here is a tutorial on how to do it.
Basically you have to use MODE_WORLD_WRITEABLE for the prefs file.
To get the context for the other package you use createPackageContext()