Skip to content
Advertisement

How to use interface to communicate between two activities

I am trying to make listener interface between two activities Act1 and Act2. Act1 will start Act2. If there is some event occurred in Act2, it will inform it to Act1. Problem is that I am starting new activity using Intent, so how Act1 will assign itself as listener to Act2’s interface?

Act1.java

JavaScript

Act2.java

JavaScript

Note: Please don’t suggest me to use fragments. I want to use activities currently.

Advertisement

Answer

Have you considered using LocalBroadcastManager?

In Act1’s onCreate:

JavaScript

In Act1’s onDestroy:

JavaScript

In Act2’s onCreate:

JavaScript

Give me a comment if the code doesn’t compile, I’m writing it by hand.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement