Situation is this:
- Activity A calls
getLocation()method from Class B.
Class B handles obtaining GPS locations.
2 Activity A should finish once Class B has finished retrieving GPS
location.
Activity A calls something like:
B.getLocation()
this.finish()
i.e. gets the location using method from B and then finishes itself. In reality, A closes before B has a chance to get the location.
How do I structure this correctly so that A waits till B has finished?
The design here is lacking. In fact, you can’t just call one
Activity‘s method for the other one, since only oneActivitycan be in foreground at the moment. Your activities should communicate usingIntents. Here’s how it should work:Activity AstartsActivity Busing anIntentActivity Bgets location and returns it toActivity A, using thesetResult()methodActivity Areads the result fromActivity Bin itsonActivityResult()methodActivity AfinishesThis feels like a better implementation. Actually, if
Activity Bdoes just get location, you can simple implement it as aServiceand bind it toActivity A. Hope this helps.