Implement interface in a service and call it in another class -Android -
i have use case in need update points(markers) on map when event occurs inside service. using interface callback method.
public interface draw { void updatepoints(context context) throws jsonexception; }
now using interface in service :
draw dfc; ............... //inside constructor of class dfc=new draw() { @override public void updatefloatingpoints(context context) throws jsonexception { system.out.println("callback in service"); customviewview.registerdpclistener(dfc); } };
now within same service, under function, passing interface input parameter i.e callback
, inside function calling
callback.updatefloatingpoints(context);
now when running service, can see callback in service
statement. till here okay.
now problem that, when callback received, want work class. let's call customview
. implemented interface in class not able receive callbacks on there. follow bare bone code of class
public class customview extends abcd implements draw { private draw dfclistner=null; public void registerdpclistener(drawpath listener) throws jsonexception { this.dfclistner = listener; if(dfclistner!=null) { system.out.println("listener initialized"); //dfclistner.updatefloatingpoints(mcontext); } else { system.out.println("listener not initialized"); } } //another functions in between on here @override public void updatefloatingpoints(context context) throws jsonexception { system.out.println("inside customview callback"); } }
how go it?
Comments
Post a Comment