Mẹo Hay

How to Save Variables in SharedPreferences – Android Studio Tutorial

Rate this post

Today we will learn how to use Shared Preferences in Android to store data. We will use a SharedPreferences.Editor to save Strings and Booleans, but you can …

Tag: sharedpreferences android, [vid_tags]

Xem Thêm Bài Viết Về Mẹo Hay Khác: https://meocongnghe.vn/meo-hay

Nguồn: https://meocongnghe.vn


  1. Thanks so much for the video, it was helpful coding flow but i gat a little problem with the code, when i back press to leave the page to the firestore ui recyclerview and click the same information again to view if the change remain constant .. it doesnt stay the same. please please check !!!!!!!!!!!! thanks

    public void SaveData() {

    SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean(BUTTON_CHANGE, UnprocessAndProcessed.isEnabled());
    Toast.makeText(this, "data saved", Toast.LENGTH_SHORT).show();
    buttonOnOff = sharedPreferences.getBoolean(BUTTON_CHANGE, false);
    if (UnprocessAndProcessed.isEnabled()){


  2. May I know what is the best way to store seekbar progress for each audio chapter . I am making an audiobook but I want it to save the position for every chapter of that book being played. I am using ExoPlayer library. Do I use sharedpreferences? But if I do, how will I be able to store multiple positions depending on what chapter it plays?


Post Comment