【发布时间】:2012-04-28 09:38:52
【问题描述】:
所以我有一个获取位置更新的后台服务,我想从我的 tabActivity 访问该服务。 (方法是静态的)
你能告诉我如何实现吗? 如果我尝试 xxxService.yyyMethod() 它不起作用。
我说的是由活动启动的后台服务,然后活动被用户关闭并重新启动。该服务绑定到相同的活动和 start() (因此即使在活动关闭后它仍然存在)。通过不工作,我的意思是该方法没有返回任何东西,而它应该是。此外,方法调用之后的任何语句都不会执行。 – Ishwar 27 秒前编辑
在活动中: 边界: *
mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
temp="LocationService bound";
locationService = ((LocationService.LocalBinder) service).getService();
locationService.setProfile(Profile);
locationService.start();
Log.e("COnnected","");
mBound = true;
}
public void onServiceDisconnected(ComponentName arg0) {
mBound = false;
}
};
*
错误区域: *
LocationService.setProfile(homeProfile); (works fine)
LocationService.getL(); (Any statement beyond this point doesnt get executed)
Log.e("Executed","LS"); settingsActivity.status.append(Boolean.toString(LocationService.isRunning()));
*
如果我注释掉第 2 行,则执行第 3 行和第 4 行,否则不执行! P.S:如果我不退出我的活动,一切正常。仅当我退出我的活动并重新启动它时才会出现此问题。
【问题讨论】:
-
“它不工作...?”.. 解释更多.. 发生了什么?
-
我说的是由activity启动的后台服务,然后activity被用户关闭并重新启动。该服务绑定到相同的活动和 start() (因此即使在活动关闭后它仍然存在)。通过不工作,我的意思是该方法没有返回任何东西,而它应该是。此外,方法调用之后的任何语句都不会执行。
-
用更多信息更新了问题
标签: android service background location