This question seems dumb, but I just cant figure out how to get the boolean, which is set by a CheckBoxPreference
in the SettingsActivity
, to my MainActivity
.
CheckBoxPreference:
<CheckBoxPreference
android:defaultValue="true"
android:key="check_box_show_idle_dialog"
android:title="Show welcome dialog" />
SettingsActivity:
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import androidx.appcompat.app.AppCompatActivity;
public class SettingsActivity extends AppCompatActivity {
public static final String KEY_PREF_CHECK_BOX_SHOW_IDLE_DIALOG = "check_box_show_idle_dialog";
Boolean show_idle_dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
//Switch Dark Mode
show_idle_dialog = sharedPreferences.getBoolean(SettingsActivity.KEY_PREF_CHECK_BOX_SHOW_IDLE_DIALOG, true);
}
}
What do I have to change in order to grab the variable in the MainActivity
? I haven't attached it, because literally could not find a single piece of code, which worked for me. Maybe it was just the wrong search terms. I would be very happy if someone has got a solution.