I am making an app where I am fetching data from a remote database and displaying it on google map. After the installation login page appears and after the credentials are verified google map appears with data fetched from database. I have saved login status and data in shared preference so that when user opens the app again after closing it it will not ask for login until user log out and also it will not ask for data until refresh button is clicked. On clicking refresh button I clear old data from preference and again save fresh data to it.
Now the problem is that whenever I uninstall and install app again I am not getting the login page and I am getting google map page with some old data.
Can anyone tell me why is this happening?
You may rarely face issue in older than Marshmallow version but you may face this issue in Marshmallow version because in Marshmallow all the app data are backed up. So first thing you need to set allowBackup as false in manifest as default is true so if you don't mention below code it will take it as true by default.
<application
android:allowBackup="false"
..
>
Then search for a folder in internal as well as external memory with the name as your app package name and delete it and restart your phone.
This will happen, when backup for the application is enabled in the manifest.
You can specify
<application
android:allowBackup="false"
... >
to disable this.
Related
In my Android app I use a set of randomly generated file names to store some data. In order to ensure that the same set of file names are generated at app restart - and are yet different for each app installation - I start off the process by picking the names as substrings from a long string of random alphanumeric characters which I generate when the app is installed. This latter string is stored in Shared Prefereneces.
As I am testing out the app I have run into a rather peculiar issue. From time-to-time I make major changes so I fully uninstall the app - and even Force Close it + clear all its data. At that point I would expect that the device would have no "prior knowledge" of the app if it is reinstalled. And yet I find that the Shared Preferences string is somehow "remembered". This causes havoc if in the interim I have changed how the file name substrings are picked up from the stored shared preferences string.
How can I ensure that the app has "zero memory" of a previously installed version that has subsequently been uninstalled?
One solution I have used in the past is to instruct Android not to do any backups via the manifest file, android:allowBackup = "false". However, I have backed away from that idea since - unless I am mistaken - it effectively means that I am stopping the user from porting their app over to a new device when they decide to change handsets.
On (re)install, your app may be restoring files from Google auto-backup (via Google Drive). To disable this feature, you can explicitly set it to false in the manifest:
<manifest ... >
...
<application android:allowBackup="false" ... >
...
</application>
</manifest>
If you'd like more granular control over what is backed up/restored and what is not, you can include or exclude specific files from the backups.
See auto backup documentation:
https://developer.android.com/guide/topics/data/autobackup#EnablingAutoBackup
If you don't want to disable auto backups, but want to reinstall with a "clean slate" (for testing purposes), you can do one of the following:
Clear app data after reinstall. This will wipe out files that were restored automatically on install
Clear app data prior to uninstall, then force a new backup (so old one gets reset) by using this command: adb shell bmgr backupnow <PACKAGE>
See how to test backups documentation:
https://developer.android.com/guide/topics/data/testingbackup#TestingBackup
To extend on this, for example mobile/src/debug/AndroidManifest.xml
<application
tools:replace="android:allowBackup"
android:allowBackup="false">
...
</application>
Alike this one can disable auto-backup for debug builds - but keep it enabled for release builds.
Simply because disabling auto-backup for release builds might not be the intended outcome.
Based on #hungryghost's suggestion the I eventually implemented a solution
Problem:Shared preferences can be remembered by Android after app reinstall and blanket instructions in the manifest along the lines of android:allowBackup = "false" are not a solution.
So why not turn the problem into a solution on its own? Here is what I do
Check shared preferences for a build specific key.
If that key is not found I do two things
Clear out all shared preferences, context.deleteSharedPrefernces(filename)
Now create that build specific key
When I make app changes that require old preferences to be forgotten I simply change the build specific key.
I'm developing an Application using Firebase analytics, authentication and DB services.
I need to save some preferences and some settings, related to the user.
Most of them are managed in a "SettingsActivity" which is similar to the sample one provided by Android Studio, but with this configuration if the user changes the device, those preferences are lost.
The app should provide a customizable experience for each user. To achieve this I'd like my preferences to be saved on Firebase insted of in local Preferences.
How can I achieve this without have to change too much my app structure?
EDIT:
Here's an example:
The user download my App on first device (Dev-A), he sign up, then he goes to settings and set first setting from A to B, and second setting from A to D.
Then he decide to download my App on a second device (Dev-B), he log in, then he goes to settings.
On Dev-A, first setting is set to B and second setting is set to D.
On Dev-B, first setting is set to A and second setting is set to A.
You will need to store this information in Firebase Database.
Use the user'd UID you get from Firebase Auth in the Database to store the settings.
The data should be under '/users/{uid}'
This way, you will persist all user specific data across devices. (Since the same UID will be presented to same authentication account)
Check this link in Firebase documentation to set the database security
You should try this library:
A implementation of SharedPreferences which syncs with Firebase database to keep your SharedPreferences in sync between multiple devices of one user and/or to back them up for app re-installs!
On my Nexus 5 running Android M Developer Preview 2, when uninstalling/reinstalling an app, the device is retrieving shared preferences I stored long ago, for instance a boolean isFirstLaunch.
The only way to clear these is to do it manually from the device settings.
Is there any change in shared preferences behavior on Android M? I can't find any documentation regarding this.
Or maybe the Android M Preview 2 ROM has a bug...
That is because Android M will feature Automatic Backups (old link).
Extract:
The automatic backup feature preserves the data your app creates on a
user device by uploading it to the user’s Google Drive account and
encrypting it. There is no charge to you or the user for data storage
and the saved data does not count towards the user's personal Drive
quota. During the M Preview period, users can store up to 25MB per
Android app.
Even already answered this question above, not mentioned the actual solution to avoid the auto backup even after uninstalling the app.
As per official, doc says to avoid auto backup need to do <application android:allowBackup="false"> in the Manifest file under application tag.:
Enabling and disabling backup
Apps that target Android 6.0 (API level 23) or higher automatically participate in Auto Backup because of the android:allowBackup attribute defaults to true. To avoid any confusion, you should explicitly set the attribute in your manifest as follows:
<manifest ... >
...
<application android:allowBackup="false" ... >
...
</application>
</manifest>
You might want to disable backups by setting this to false if your app can recreate its state through some other mechanism or when your app deals with sensitive information that should not be backed up
Open settings -> Backup & reset -> automatic restore -> off
if is on then app cache and database will be restore.
I'm working on an Android app where everything is stored locally. (There is no account registration system). If a user tapped the Clear data and Clear cache option under Settings > Applications > Manage Application the on boarding process will show up again because the local storage got reset.
What options do developers have to check if a user is really a first time user and didn't just reset or reinstalled the app?
With server -
Send a unique device id to the server and save its state.
Without server (in your case) -
The only option for to save it after reinstall/clear cache is to add the permission to read/write sd card and hide it in the device where he wont delete it. I've hide it in data/data/my_package_name_backwords, be if i wouldnt do it backwords then the system deletes this folder when the user uninstall my app.
While I would advice against such an implementation, since users have the right to 'reset' the application and it is expected behavior to revisit the first launch screen, the following option would be feasible:
Use a web service and store the device id upon completing the first launch. When the application is launched, check if the device id is already present in the the database. For obtaining the device id, I would like to refer to this answer
Dont allow the user to clear the application data via ManageActivity. Allow the user to delete the data only through the app.
If the user clears the Data being inside the app, next time the user launches the app, will create the credentials and store it locally!
If you want the user not to clear the data by clearing the cache then create a dummy Activity that inturn lanuches your MainActivity and in the manifest declare this tag!
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:manageSpaceActivity="com.urapp.DummyActivity"
android:theme="#style/AppTheme" >
...
...
</application>
Thats it! Now, when the user tries to clear the data it will launch your MainActivity!
I have this android app with user login and app settings.
app settings are save in default location com.package_preference.xml
when user logins. he or she can set the app settings like notification. or vibrate.
my problem is when another user logins every app settings set by the last user logged in will be use since it was stored localy.
any ways to handle this issue? or better ways to avoid this problems?
I was thingking saving that file on sqlite but that was a lot of work to do.
or name the preference file like user_id_preference.xml but i dont think this is feasible since app preference are save as com.package_preference.xml