Frage

What's the best way for an Activity to respond to events from another Activity? For example, suppose I get to Activity B from Activity A. B has a button that does something (specifically, send some info via http request). Now when I go back to Activity A, I need something to detect that this button has been pressed to refresh some new data via another http call.

I could place the update code in onResume of Activity A but that would trigger even if the button was not pressed. If I need to do http requests, placing it in onResume would result in requests all the time not just when the button is pressed. Not very efficient.

Are callbacks the way to go or does something work better?

War es hilfreich?

Lösung

I believe this should help. You can return results from an activity by starting it with startActivityForResult(intent, resultId)

http://developer.android.com/training/basics/intents/result.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top