0

For example, i do a login operation in activity B and want to update the ui in activity A. How to do that?

Until now, the method i use is to register a broadcast receiver in activity A and unregister it in onDestroy. It works fine, but android always give a warning about leaking broadcast.

Frank Cheng
  • 5,928
  • 9
  • 52
  • 80
  • Why not just wait until Activity A is in the foreground before updating its UI? – EJK Dec 05 '14 at 00:41
  • look this. http://stackoverflow.com/questions/2468874/how-can-i-update-information-in-an-android-activity-from-a-background-service – kksal55 Dec 05 '14 at 00:43
  • That does not seem to apply here. That question asks "how to update an activity from a background service". Your question is about updating an activity when the activity itself is in the background. In fact there is not even a service in the picture in your case. So again I ask - why not simply wait until activity A is in the foreground? – EJK Dec 05 '14 at 00:46
  • @EJK If i update activity when it's brought to front again, i need to save the state whether the data is changed, right? – Frank Cheng Dec 05 '14 at 00:51
  • I'm not sure I follow. The approach you describe is very uncommon. Typically activity UIs are only updated upon a lifecycle callback (onCreate, onResume, etc) on the activity itself. It does not sound like your app is doing anything so sophisticated that would warrant such a radical approach. Perhaps if you posted your code, we could discuss this further. – EJK Dec 05 '14 at 01:01
  • @EJK What i asked it like [this](http://stackoverflow.com/questions/7887169/android-when-to-register-unregister-broadcast-receivers-created-in-an-activity). But i don't think it's a good solution to put unregister in onDestroy. – Frank Cheng Dec 05 '14 at 01:10
  • 1
    BroadcastReceivers are simply not a good fit for what you are doing. – EJK Dec 05 '14 at 01:19

0 Answers0