1

I have activity which contain 3 fragment. when the activity onPaused the 3 fragment set a value to a variable.

I want to check that var in the onPause activity.

but the problem that onPause activity called first and then the fragment onPause called.

How to solve that ?

so i need to run a function when all onPause function finish running ?

thanks

1 Answer 1

1

You could define an interface in your fragment and make the activity implement that interface. Then define one method like variableWasSet() in that interface and call it in onPause() in your fragment after you set your variable. That's a recommended way for communication between fragments.

Or use an event bus system for communication between fragments and activities. Like otto or EventBus.

3
  • thank you for your answer. the first approach will call onPause mutliple times, so it's not suite my needs .regarding to second approach: i will have look at this.
    – david
    Oct 5, 2015 at 7:42
  • I guess this happens because you have 3 instances of the same fragment? Using an event bus cause the same effect then. If you indeed have 3 instances then you would have to handle this yourself by checking if 'something' was already done.
    – Jens
    Oct 5, 2015 at 7:48
  • actually i have more than 3 instances. and the number of fragments are changed according to the user activities. so it will be a little bit difficult to handle that. thank you for your time
    – david
    Oct 5, 2015 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.