Android Firebase user persistance between updates

Viewed 189

I'm using Firebase on my Android app & iOS.

When the user start the app, I create an anonymous user. On iOS when you delete the app Firebase will get the last user because its store the session inside the device's keychain.

On Android when I delete and reinstall my app, the user is always null using :

FirebaseAuth.getInstance().currentUser

I have search the web and found that it might be possible using android:allowBackup="true" in the app's manifest. But this has no effect on my app.

This my application manifest :

    <application
        android:networkSecurityConfig="@xml/network_security_config"
        android:allowBackup="true"
        android:allowClearUserData="false"
        android:hardwareAccelerated="true"
        android:fullBackupContent="true"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:largeHeap="true"
        android:theme="@style/AppTheme">
...

Any ideas on how I can keep the user between app deletion ? Wether it is an anonymous or a sign up user ? I have implemented dynamic links and invitation, if the user has 2 devices and one on Android he can invites himself all day long just by deleting the application and get rewards for free.

1 Answers

When the user start the app, I create an anonymous user. On iOS when you delete the app Firebase will get the last user because its store the session inside the device's keychain.

When using Firebase anonymous authentication, you only create temporary anonymous accounts to authenticate your users with Firebase. Anonymous authentication accounts don't persist across application uninstalls. When an application is uninstalled, everything that was saved locally will be deleted, including the anonymous auth token that identifies that account. Unfortunatelly, there is no easy way to reclaim that token for the user.

However, starting from Android 6.0 (API level 23), the Android operating system preserves app data by uploading it to the user's Google Drive, which means that when using:

android:allowBackup="true"

You'll have a local copy on user's device. Here is the official documentation regarding Android autobackup. Without seeing your code, it's hard to say why it's not working but it definitely should. This is a post in which is explained how you can disable it:

Please also note that if you clear the cache, "No data previously saved by the app will survive".

Related