Home OnSharedPreferenceChangeListener implemented between apps with sharedUserID?
Reply: 1

OnSharedPreferenceChangeListener implemented between apps with sharedUserID?

Elisabeth Published in 2017-11-15 00:52:08Z

I have App A and App B under sharedUserId. In App B, I would like to get the sharedPreferences of A, when they change. Right now I can get app A's sharedPreferences, but only on recompile. Is this possible?

This is an example of what I'm attempting in app B:

// get Context of Shared App
     sharedContext = this.createPackageContext("com.app.A",Context.CONTEXT_IGNORE_SECURITY);
// get desired preferences from app A
     myPrefs = sharedContext.getSharedPreferences(PREFERENCES,Context.MODE_PRIVATE);
// keeping local copy of this listener
     listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
     public void onSharedPreferenceChanged(SharedPreferences myPrefs, String key) {
          if (key.equals(PREFERENCES)) {
                       // Do something
               Log.d("Test", "preferences were updated");
// register listener
Elisabeth Reply to 2017-11-16 05:18:50Z

set android:process in the manifest of each app.

Also key.equals(PREFERENCES) should be the name of the specific preference to grab, key.equals("key:example") rather than the name of the shared Preference.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304973 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO