Home OnSharedPreferenceChangeListener implemented between apps with sharedUserID?
Reply: 0

OnSharedPreferenceChangeListener implemented between apps with sharedUserID?

user1010
1#
user1010 Published in July 17, 2018, 11:10 pm

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
myPrefs.registerOnSharedPreferenceChangeListener(listener);
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO