java 监听器实现原理
实例二:
@Override
public void onStart(Intent intent, int startid) {
super.onStart(intent, startid);
locationService = ((LocationApplication) getApplication()).locationService;
//获取locationservice实例,建议应用中只初始化1个location实例,然后使用,可以参考其他示例的activity,都是通过此种方式获取locationservice实例的
locationService.registerListener(mListener); //注册监听
if (type == 0) {
locationService.setLocationOption(locationService.getDefaultLocationClientOption());
} else if (type == 1) {
locationService.setLocationOption(locationService.getOption());
}
}
@Override
public void onDestroy() {
Log.i("warn", "ondestroy");
locationService.stop(); //停止定位服务
locationService.unregisterListener(mListener); //注销掉监听
}