Search code examples
javaandroidkey-value-store

how to store a value permanently in android?


I am trying to make an initial synchronisation type of task. That is, the method can only be executed once when app is installed and not again. So I want to store a value called which has default value 0 but when sync method is called it becomes 1. Storing the variable on sd card is what I found but I think it is too much for storing one integer variable Any suggestion on how to do it ?


Solution

  • There are multiple ways to store the values permanently in Android application. But the best solution in your case is SharedPreference.

    https://developer.android.com/reference/android/content/SharedPreferences.html

    You can store the values in all primitive types.

    This data only gets removed if you uninstall the app or Clear data of your app from Settings.