0

I am developing an app where I am keeping boolean flag in SharedPreferences to check if current session is active or not. Based on this flag user gets navigated to either Home screen or Login screen after Splash screen is being shown.

This is working fine but one of our client has reported that his app keeps his user logged in even after uninstallation and re-installation of his app.

Steps he followed

  • Install app
  • Login using valid credentials
  • Uninstall app from settings
  • Re-install app using apk given by me
  • Open app

I think when we uninstall app, its data gets cleared (including shared preferences), and this is working fine one other devices like Pixel 2, OnePlus 3 which are having same Android OS 8.0.

This is how I handled navigation. Here SessionManager is singleton (object in Kotlin) which stores isSessionActive flag. isSessionActive flag gets its value from SharedPreferences when application starts

val intent: Intent = if (SessionManager.isSessionActive) {
      Intent(this, MainActivity::class.java)
} else {
      Intent(this, LoginActivity::class.java)
}
startActivity(intent)

Can you suggest possible root cause of this behaviour and solution for this?

silwar
  • 6,470
  • 3
  • 46
  • 66
  • 2
    Possible duplicate of [SharedPreferences are not being cleared when I uninstall](https://stackoverflow.com/questions/35517239/sharedpreferences-are-not-being-cleared-when-i-uninstall) – AskNilesh Mar 28 '18 at 06:37
  • 1
    [**`android:allowBackup=false`**](https://developer.android.com/guide/topics/manifest/application-element.html#allowbackup) – AskNilesh Mar 28 '18 at 06:38
  • 1
    @NileshRathod I made changes as per your suggestion. Let me check with my client once then i will let you know if this solution is working for me or not – silwar Mar 29 '18 at 06:59
  • ok let me know if any issue – AskNilesh Mar 29 '18 at 07:00

2 Answers2

2

Probably due to the android:allowBackup=false

Check SharedPreferences are not being cleared when I uninstall

neteinstein
  • 17,529
  • 11
  • 93
  • 123
0

To clear your app data.Add the following

         try {  // clearing app data
        Runtime runtime = Runtime.getRuntime();
        runtime.exec("pm clear your package name");
       //e.g "pm com.example.test"
    } catch (Exception e) {
        e.printStackTrace();
    }
Rohit Rajpal
  • 106
  • 1
  • 4