Hi Friends,
I have created two android applications. In the first application , I am creating a shared preferences and registering to the onSharedPreferenceChangListner(). In the Second application, I am trying to add some data to the shared preferences created by first application. In the second application, if we change shared preference value of the first application, the listener of the shared preference registered in first application is not getting invoked.
The problem is while second application adding data to the shared preferences of the first application, the listener of the shared preferences registered in first application is not getting invoked. It is very urgent. If anyone have any solution please help me. Any help is appreciated.
My code is as follows
First Application
OnSharedPreferenceChangeListener sp = getSharedPreferences("mySp",Context.MODE_WORLD_READABLE);
SharedPreferences.Editor spEd=sp.edit();
s pEd.putInt("Biswa",424);
spEd.commit();
OnSharedPreferenceChangeListener listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
msg = Toast.makeText(SharedPreferencesDemo.this, "SharedPreference Changed", Toast.LENGTH_LONG);
msg.show();
}
};
sp.registerOnSharedPreferenceChangeListener(listener);
}
Second Application
Context otherAppsContext = createPackageContext("com.android.sharedPreferencesDemo",Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences sp = otherAppsContext.getSharedPreferences("mySp",Context.MODE_WORLD_WRITEABLE);
SharedPreferences.Editor spEd=sp.edit();
//Adding Values
spEd.putInt("Raja",242);
spEd.commit();
Thanks & Regards,
Biswa
I have created two android applications. In the first application , I am creating a shared preferences and registering to the onSharedPreferenceChangListner(). In the Second application, I am trying to add some data to the shared preferences created by first application. In the second application, if we change shared preference value of the first application, the listener of the shared preference registered in first application is not getting invoked.
The problem is while second application adding data to the shared preferences of the first application, the listener of the shared preferences registered in first application is not getting invoked. It is very urgent. If anyone have any solution please help me. Any help is appreciated.
My code is as follows
First Application
OnSharedPreferenceChangeListener sp = getSharedPreferences("mySp",Context.MODE_WORLD_READABLE);
SharedPreferences.Editor spEd=sp.edit();
s pEd.putInt("Biswa",424);
spEd.commit();
OnSharedPreferenceChangeListener listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
msg = Toast.makeText(SharedPreferencesDemo.this, "SharedPreference Changed", Toast.LENGTH_LONG);
msg.show();
}
};
sp.registerOnSharedPreferenceChangeListener(listener);
}
Second Application
Context otherAppsContext = createPackageContext("com.android.sharedPreferencesDemo",Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences sp = otherAppsContext.getSharedPreferences("mySp",Context.MODE_WORLD_WRITEABLE);
SharedPreferences.Editor spEd=sp.edit();
//Adding Values
spEd.putInt("Raja",242);
spEd.commit();
Thanks & Regards,
Biswa