Redeem Now
Read More
Read now

How to use interface with handler to transfer data between activity and fragment


Interfaces are more flexible than base classes because you can define a single implementation that can implement multiple interfacesInterfaces are better in situations in which you do not have to inherit implementation from a base class.Interfaces are useful when you cannot use class inheritance.

Make an interface like given below where we define multiple methods with different parameters.

Any fragment that should pass data back to its containing activity should declare an interface to handle and pass the data.Then make sure your containing activity implements those interfaces. For example:

Here, ((Your Fragment which implements the interface )).getFileCode(Parameters which you want to be transferred) replace fragment with the container and commit. In your fragment where getFileCode you will get your data in your replace fragment.


. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again