Bug 27266 - Preserve data/cache not respected
Summary: Preserve data/cache not respected
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 5.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Ben Beckley
Depends on:
Reported: 2015-02-20 14:41 UTC by Eshaan
Modified: 2017-12-26 17:10 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 27266 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Eshaan 2015-02-20 14:41:43 UTC
I have preserve data/cache checked in the settings but whenever I do a debug build onto my android device it always uninstalls the old apk and reinstalls the new one.
Comment 1 Jonathan Pryor 2015-02-20 14:59:53 UTC
The Preserve data/cache option has nothing to do with whether the .apk is uninstalled or not.

The Preserve data/cache option controls whether the .apk is uninstalled with `adb uninstall -k` or not:

>    ('-k' means keep the data and cache directories)

The .apk contains all Android resources, assets, and Java code. If any of these changes for any reason -- e.g. resources are added or changed, or a C# class was altered to override a new Java method -- then the .apk MUST be rebuilt and redeployed. There is no way to avoid it.
Comment 2 Eshaan 2015-02-20 15:54:26 UTC
so there's no way to change it to just install with -r? It seems like my data is getting wiped every time I deploy a build.
Comment 3 Eshaan 2015-02-26 15:59:29 UTC
also this would be better because when you force an uninstall/install any widgets/home screen shortcuts that had been set are removed. If you guys need proof that my data is getting removed when i push builds I can send a video or something.
Comment 4 Ben Beckley 2015-02-27 16:42:34 UTC
Ran some manual tests and found that "preserve data/cache between application deploys" was working as expected.

Used monodroid-samples/Notepad on Debug mode and followed the steps below:

Part 1:
install app that preserves data/cache
go to "preferences > projects > android > tun on preserve data/cache…"
clean and rebuild app
deploy app and store some data

Part 2:
go to "preferences > projects > android > turn on preserve data/cache…”
clean and rebuild
redeploy app with preserve data/cache on via XS
observe that data should be preserved
stop debugging

Part 3:
go to "preferences > projects > android > tun off preserve data/cache…”
clean and rebuild
redeploy app with preserve data/cache off via XS
observe that data is gone

Link to sample:

Development environment:
Comment 5 Eshaan 2015-03-05 21:03:10 UTC
Try this on the google n6 with latest lollipop - it seems to only happen on this device.
Comment 6 Ben Beckley 2015-03-06 12:44:03 UTC
Followed the same steps as listed in Comment 4 with a Nexus 6 (5.0.1) and could not reproduce the issue. Everything worked as expected.
Comment 7 Eshaan 2015-03-06 13:30:14 UTC
I will try with the notepad sample app and get back to you.
Comment 8 Eshaan 2015-03-06 14:13:54 UTC
I reproduced the bug. 

1. Install notepad app -> make a note.
2. make some changes to the xml in the notepad app (I added <Button android:layout_width="4dp"
in node_edit.xml)
3. push the app with xamarin
4. The note you previously created will be gone (on nexus 6 lollipop).

if you then push builds without making changes it does preserve data. but if you make changes it doesn't.
Comment 9 Eshaan 2015-03-06 14:16:22 UTC
Also ensure that xamarin says "removing previous version of the application" when you are pushing - as I believe this is where the data gets removed.
Comment 10 Ben Beckley 2015-03-09 11:38:13 UTC
Followed the steps in Comment 8 with a Nexus 6 (5.0.1) and was unable to reproduce the bug with preserve data/cache checked. Also ensured that it was "removing previous version of the application" as per the suggestion in Comment 9.

Could you please give details on your Xamarin Studio setup? Go to the tab option "About Xamarin Studio > Show Details" and then provide the information. It will look like this:
Comment 11 Eshaan 2015-03-09 14:38:21 UTC
Hmm maybe it's just something wrong with the phone.. like because it's rooted or something. Let me try adb uninstall/reinstall with -k and see if that works. here is my xamarin setup.

Comment 12 Jonathan Pryor 2017-02-14 01:24:03 UTC
> so there's no way to change it to just install with -r? 

Long delay, I realize... At the time, I tried to figure out why we didn't use `adb install -r`, and couldn't find an answer.

Now, I might: `adb install -r` is unreliable, at least for me:


If `adb install -r PACKAGE` doesn't actually make the updated package usable on the device, it's *broken*, and that's what I and a co-worker had to debug through for *hours* last week...
Comment 13 dpedrinha 2017-08-09 01:48:39 UTC
Different app, different device, app data is always wiped, including SharedPreferences and GoogleApiClient data. Need to login every time.

Please fix it. We two are not the only one complaining about it.
Comment 14 Avi Sadde 2017-12-26 17:10:10 UTC
Have exactly the same problem:
- "Preserve application data" - CHECKED
- Using Android Authenticator component (extends AbstractAccountAuthenticator).
- Need to re-login to the app after EVERY deploy to the device.

I understand that the issue 'adb install -r' is unreliable on some cases. But at least give it as an option...
I believe it's the same as issue described in Bug 32443