0

I am using shared preference variable in one (first) file and onSharedPreferenceChanged in an other (second) file. Based on the value of shared preference variable value, i want to perform some task. Whenever sharedpreference variable value is changed, onSharedPreferenceChanged in the second file will be called internally?. if not, how can i perform task in second file immediately after change in shared preference variable in first file?

Ravi
  • 34,851
  • 21
  • 122
  • 183
Abhishek
  • 71
  • 8
  • your question is still unclear, as we know we can update the view of any activity if its in foreground else we cant, so please elobrate more about your question – Rahul Dec 07 '15 at 09:39
  • lets say there are two screens , first screen has three options.operations related to each option is performed in separate files. Upon clicking the second option, it will launch new screen(second screen) which performs certain operation after clicking the options available in second screen. i have clicked a option in second screen ,it performed some operation and shared preference variable value is changed during this process. onSharedpreferencechanged is in other file(file of 3rd option in first screen). does onSharedpreferencechanged gets called when the sharedpreference is changed? – Abhishek Dec 07 '15 at 09:48
  • if i go to the first screen, then it will call onresume of the 3rd option related file. but i dont want go to first screen. while i am in second screen, perform some operation, change shared preference value, onSharedpreferencechanged in the other file should get called immediately and perform the operation related to that change in background – Abhishek Dec 07 '15 at 09:48
  • i know its too long but couldnt find any better way to explain. hope it is clear now – Abhishek Dec 07 '15 at 09:49
  • did you tried on activityResult ? – Rahul Dec 07 '15 at 09:50
  • prefs.registerOnSharedPreferenceChangeListener(this) – Ramesh Bhupathi Dec 07 '15 at 09:57
  • @RameshBhupathi i have put prefs.registerOnSharedPreferenceChangeListener in onresume method. when ever i go to second screen, onresume goes to onpuase where i am unregistering the sharedpreferencechangelistener. So will it call onSharedpreferencechanged as it is unregistered? – Abhishek Dec 07 '15 at 10:46
  • @Rah No. what is it? – Abhishek Dec 07 '15 at 10:47
  • firstActivity(ButtonClick) -->secondActivity(Finish()) --> firstActivity(with result or updated value can be used in firstActivity to update Ui),,,,,,,,in easy way just to get return value from activity. – Rahul Dec 07 '15 at 11:56

0 Answers0