0

I start Activity B from Activity A. Activity B does something to my Data and at some point I call finish();, however Activity B is still doing something with my Database in the background and when its finished I want to get notified in Activity A, that this process is finished.

Because there is no way to my knowledge to call a method from another activity I tried to solve this problem with startActivityForResult but because Im calling finish(); before actually setting a Result this does not seem to work either.

Any Idea on how to solve this problem?

Jonas
  • 7,089
  • 15
  • 49
  • 110
  • 1
    This use case is a little bit weird. Could you explain more about this use case and why you need to do some background process started in activity B but notified in activity A? – Marc Estrada May 20 '18 at 21:39
  • Certainly there are tips and tricks that will do what you are asking, but I suspect your UX scenario is not well executed. What long process could you be doing in activity B that needs to inform activity A? – Barns May 20 '18 at 22:14
  • Well im using a realtime database (Firebase) and in Activity A I display an Object and in Activity B I can modify it and update it on the Database. After finishing I wanted to finish the Activity and let the updating process be done in the background. Once this is finished the Activity A should be notified, that there is new Data. – Jonas May 21 '18 at 12:41

2 Answers2

2

Don't do task in Activity that may live beyond Activity lifecycle. In that case do your task in Service and notify the Result to Activity. There are some ways to communicate between Activity and Service using BroadcastReceiver , Messenger, Handler, Bound Service . You can also use EventBus library for this communication.

Check this and this thread for communicating between Activity and Service

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50
0

Try to close your database, and after it's been closed successfully, 'notify' your activity A about this result and finish activity. Quite an imprecise question, frankly :P And if you want to invoke some method from another class, pass the activity's Context.

spectral
  • 11
  • 1
  • 3