Jonas
Jonas

Reputation: 7945

Activity B notify a Activity A after calling finish()

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?

Upvotes: 0

Views: 103

Answers (2)

Abu Yousuf
Abu Yousuf

Reputation: 6107

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

Upvotes: 2

spectral
spectral

Reputation: 21

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.

Upvotes: 0

Related Questions