Reputation: 3327
I have used SharedPreferences to check whether it is already logged in or not. But after I logged in and then uninstall the app, it always gives true value while reinstalling the app and login page is not shown. Why is it? Isn't it true that when the app is uninstalled, the value in sharedPreference should have gone too? It works in unsigned apk (ie when you install the app directly through android studio) but as soon as I use signed apk, the problem appears. It is happening in nokia 5 and some other devices but works perfectly fine in other android devices. How can I solve it?
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
**//always gives true value here...**
Log.e("loginStatus", pref.getBoolean("activity_executed", false) + "");
if (pref.getBoolean("activity_executed", false)) {
Log.e("loginStatus", pref.getBoolean("activity_executed", false) + "");
Intent intent = new Intent(this, LiveTrack.class);
startActivity(intent);
finish();
} else {
Log.e("loginStatus", "notlogin");
}
}
}
Upvotes: 3
Views: 1873
Reputation: 4132
It is the problem with some of the devices.Try deleting the data files manually when user quits the app.
File sharedPreferenceFile = new File("/data/data/"+ getPackageName()+ "/shared_prefs/");
File[] listFiles = sharedPreferenceFile.listFiles();
for (File file : listFiles) {
file.delete();
}
Also make sure you havent turned on the allowBackup as true because from android-23 by default backup stores app's data including preferences to cloud.Later when you uninstall then reinstall newer version you will to use restored preferences.
<application ...
android:allowBackup="false">
</application>
Upvotes: 5