4

According to Google druging developing instant apps

"Best practices" is "Keeping user state after app installation"

https://developer.android.com/topic/instant-apps/ux-best-practices.html#keep_user_state_after_app_installation

I tried to use Internal Storage in instant app and installed app, but it doesn't work, because there are different paths:

  • instant app: /data/user/0/com.google.android.instantapps.supervisor/files/hosted/package_name/files
  • installed app: /data/user/0/package_name/files

Of course, external storage also doesn't work, because instant app could receive permission to it.

Does anybody know or has idea how to resolve that problem, which should be solved according to Google "Best practices"?

Stonek
  • 643
  • 9
  • 14
  • 1
    You're kidding, right? You can't store data from Instant Apps. The only purpose of instant apps is to make the user do his/her thing and leave. Ezee Pzee! – Daksh Gargas Aug 02 '17 at 09:25
  • 2
    No, I'm not kidding .. so explain me how to "Keep user state after app installation" and "When users install the app, make sure that you transfer their stored app state to the app using cookies or local storage" hmm? – Stonek Aug 02 '17 at 09:47
  • Use `SharedPreferences` then. But that should only be done when user has **installed** the application – Daksh Gargas Aug 02 '17 at 09:53
  • 2
    Why do you think that should only be done with installed app? Should I use `Context.MODE_PRIVATE` in `SharedPreferences`? I asked because I tried this solution and also have empty data between apps ;/ – Stonek Aug 02 '17 at 10:28
  • Because as soon as the user leaves the `Instant App` the system clears out all of it's components and the files(including source code). So there won't be any room for such. Have you read the documentation? If not, I guess you should. – Daksh Gargas Aug 02 '17 at 10:43
  • 2
    No, I don't agree with you, because if you come back to Instant App you can restore all data saved before. Yes, I've read, even many times, but any solution I know is not working, unfortunately .. – Stonek Aug 02 '17 at 11:05
  • Kindly share that link(from where you've read this). Thanks! – Daksh Gargas Aug 02 '17 at 11:07
  • There is the only one place where I found it: https://developer.android.com/topic/instant-apps/ux-best-practices.html#keep_user_state_after_app_installation – Stonek Aug 02 '17 at 11:16
  • It's not there. You are just making that up. And just to add some to your knowledge **whenever the system launches an instant app, it takes some (not all) piece of code(source) from Google Play Store and then compiles it to display a single activity. I repeat SINGLE ACTIVITY** Take care! – Daksh Gargas Aug 02 '17 at 11:40
  • According to https://developer.android.com/topic/instant-apps/prepare.html#restricted_features – ijustyce Aug 09 '17 at 08:30
  • @Stonek what best practice you followed for this? Please advice – Ajit Dec 18 '17 at 09:52
  • @Ajit using instant app cookie (https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat) need to update Instant Apps Development SDK to 1.1.0 – Stonek Dec 20 '17 at 13:18

4 Answers4

4

You can migrate data from InstantApp to installed app using StorageApi, example is here: google sample storage api. Just access InstantApps.getInstantAppsClient(this).instantAppData and you have it, addOnSuccessListener and here you go.

Sebas LG
  • 1,715
  • 1
  • 18
  • 31
3

Storage transfer from instant to installed app happens automatically on O+, but for platforms below O, you need to use this API. Please refer to Android Instant Apps FAQ: “How do I transfer data from an instant app to an installed app?”

https://developer.android.com/topic/instant-apps/faqs.html

For devices running Android 8.0 (API level 26) or higher, the instant app's data is transferred automatically when the APK installation begins. For devices running Android 7.1.1 (API level 25) or lower, call compatibility API in Google Play Services.

Julia K
  • 561
  • 5
  • 11
2

The only option I can think of is saving that info on your server somehow and when the user installs the app recover it and continue where he left of. This is something that Google specified for apps with shopping carts (for example), where after the install the user will be able to continue shopping without losing any articles he may have chosen already. Also remember that through SmartLock you can save an account on the device and recover it later in the installed app. Hope this helps!

Jorge Roldan
  • 21
  • 1
  • 3
0

I have been using couchbase lite to save my data on couchdb server then writing a filter then run pullReplication from the server using a sync gateway you can check out how it works here. Then in the android app i use the SharedPreferences to check if its the apps first run then run the sync

Isaac Obella
  • 2,613
  • 2
  • 16
  • 29