How to use LocalBroadcastManager?

后端 未结 13 3197
天命终不由人
天命终不由人 2020-11-21 04:15

How to use/locate LocalBroadcastManager as described in google docs and Service broadcast doc?

I tried to google it, but there is no code available to s

13条回答
  •  [愿得一人]
    2020-11-21 04:54

    we can also use interface for same as broadcastManger here i am sharing the testd code for broadcastManager but by interface.

    first make an interface like:

    public interface MyInterface {
         void GetName(String name);
    }
    

    2-this is the first class that need implementation

    public class First implements MyInterface{
    
        MyInterface interfc;    
        public static void main(String[] args) {
          First f=new First();      
          Second s=new Second();
          f.initIterface(s);
          f.GetName("Paddy");
      }
      private void initIterface(MyInterface interfc){
        this.interfc=interfc;
      }
      public void GetName(String name) {
        System.out.println("first "+name);
        interfc.GetName(name);  
      }
    }
    

    3-here is the the second class that implement the same interface whose method call automatically

    public class Second implements MyInterface{
       public void GetName(String name) {
         System.out.println("Second"+name);
       }
    }
    

    so by this approach we can use the interface functioning same as broadcastManager.

提交回复
热议问题