Listen to same result from different Android Fragments -


There are 2 pieces I'm calling a service from I slice 1. I have a result Resistor in 1 segment that listens to the result and will call onReiveiveResult method1 () .

I want to get a result recipient in section 2 to listen to same response , but onReiveiveResult method2 ()

How do I get it? You can specify an interface:

  interface receiver { Cancel cancellation (); }  

Apply your two pieces to this interface. In the implementation of the Phasement 1, only method 1 (), and the implementation of Fragment 2, call method 2 () says:

  in the public class Fragment 1 extended component receiver {// to register receiver And remember to remove it (like atet and ondate respectively). Private MyReceiver mBroadcast = New MyReceiver (this); Result on public zeros () {this.method1 (); }} In the public class Fragment 2, the receiver enforcing the scheme has been expanded (// Remember to register and delete the receiver (eg Attache and OnDet respectively) Private MyReceiver mBroadcast = New MyReceiver (this); Public Result on zero () {this.method2 ();}}  

Then specify the broadcast receiver as a standalone (or inner static) class, such as Fragment 1 and Fragment 2 Both instant it Public class: Mycesever Broadcast Receiver (Private Receiver Mfregrment; Public MyReceiver) Public Nil (reference reference, intention intent) on {mFragment = fragment;} {If ( Intent.getAction (.) Equal (YOUR_ACTION) {mFragment.onResult ()}}}}


Comments