Skip to content

Instantly share code, notes, and snippets.

@alome007
Last active January 19, 2023 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alome007/cc1869f2c970a2d82ece3b7e5796b8d8 to your computer and use it in GitHub Desktop.
Save alome007/cc1869f2c970a2d82ece3b7e5796b8d8 to your computer and use it in GitHub Desktop.
Using Encrypted SharedPreferences
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
private val sharedPreferencesHelper by lazy {
SharedPreferencesHelper()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
sharedPreferencesHelper.saveData(applicationContext, "USER_NAME", "Astrocoder")
sharedPreferencesHelper.saveData(applicationContext, "ACCESS_TOKEN", "MY_ACCESS_TOKEN")
val username = sharedPreferencesHelper.getData(applicationContext, "USER_NAME")
val accessToken = sharedPreferencesHelper.getData(applicationContext, "ACCESS_TOKEN")
Log.d("TAG", "The username is $username and the access token is $accessToken")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment