Load another apps Shared Preferences

Viewed 41

I have 2 apps, app A and app B. App A saves some data in SharedPreferences using the following code:

SharedPreferences prefs = getSharedPreferences("sharedPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("string1", string1);
editor.putBoolean("switch1", switch1);
editor.apply();

App B loads the App A's data through:

Context con = createPackageContext("com.appApackage", 0);
SharedPreferences pref = con.getSharedPreferences("sharedPrefs", MODE_PRIVATE);
String text = pref.getString("string1","No Value");
boolean switchOnOff = pref.getBoolean("switch1", false);

The problem is that the app B loads data only once (only one time, after new fresh start), and if I change shared preferences in app A, the app B will load the same data it loaded the first time. i.e. it doesn't load new data until it's restarted again. Is there any solution for this problem?

0 Answers
Related