1

How to I read SharedPreferences value from another activity?

I have got setting.calss when i choose which activity start first it works great...

how to i read Preferences from other activities?

    final SharedPreferences settings = getPreferences(MODE_PRIVATE);
    int choice = settings.getInt("language", -1);

Open Dialog 3 activities:

    String[] activities = { "Activity 1", "Activity 2", "Activity 3" };

OnClick:

            @Override
            public void onClick(DialogInterface dialog, int which) {
                SharedPreferences.Editor editor = settings.edit();
                editor.putInt("language", which);
                editor.commit();
                launchActivity(which);
            }
            }).show();
    } else {
        // start the activity and close this activity
        launchActivity(choice);
    }
}
user1710911
  • 657
  • 3
  • 7
  • 15

0 Answers0