我有一个用例,当服务中发生某个事件时,我需要在地图上更新点(标记)。因为那是使用接口回调方法。
public interface draw
{
void updatePoints(Context context) throws JSONException;
}
现在我在我的服务中使用这个界面:
draw dfc;
...............
//Inside a constructor of a class
dfc=new draw() {
@Override
public void updateFloatingPoints(Context context) throws JSONException {
System.out.println("Callback in Service");
CustomViewView.registerDPCListener(dfc);
}
};
现在在同一个服务中,在某个函数下,我将接口作为输入参数传递,即callback
,并在该函数内调用
callback.updateFloatingPoints(context);
现在,在运行服务时,我可以看到callback in Service
语句。直到这里一切都还好。
现在的问题是,当收到回调时,我想做一些其他的工作。我们称之为CustomView
。我也在该类中实现了接口,但是我无法在那里接收回调。 Follow是该类的裸骨代码
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 is not initialized");
}
}
//Another functions in between over here
@Override
public void updateFloatingPoints(Context context) throws JSONException {
System.out.println("Inside CustomView callback");
}
}
我该如何解决?