0

I am new to the Android Development. I have started developing an app using Android Studio, and i have created a project using Navigation Drawer Activity. And there is a SettingsActivity.java and pref_general.xml associated with it, and in the pref_general.xml there is a section where the user can put his name and that is saved somewhere in the sharedPreferences. My Question is i want to display the current value in another activity in the app, but cannot seem to get the value i want. Can anybody help, as i don't know where to go from here. Thank You in advance.

Here is SettingsActivity.java

private void bindPreferenceSummaryToValue(Preference preference) {
        // Set the listener to watch for value changes.
        preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

        // Trigger the listener immediately with the preference's
        // current value.
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));

        sharedPreferences = getSharedPreferences("appuserName", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit().putString("appuserName", String.valueOf(sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""))));
        editor.apply();
    }

MainActivity.java

SharedPreferences sharedPreferences = getSharedPreferences("appuserName", Context.MODE_PRIVATE);
        String appsUserName = sharedPreferences.getString("appuserName", " ");
        appuserName.setText(" " + appsUserName);
George Doe
  • 21
  • 1

0 Answers0