添加建议的方法(doBindService()
和doUnbindService()
)以及无效的调用后)@Nick Campion建议的here
我已经尝试了一段时间来运行这项服务,但似乎没有任何工作 - 我知道我可能错过了分号或其他东西:)
程序调用{{1}},然后日志显示日志消息......应用程序继续运行而不显示服务。我找不到服务提前任务杀手。 HELP !!!
startNotificationService()
<service
android:icon="@drawable/icon"
android:label="Smart Spdate Service"
android:name="notifyService">
<intent-filter
android:label="FULL_PATH_NAME_HERE.updateService">
</intent-filter>
</service>
Log.v("NOTICE", "Notification Service was not found running - starting");
//startService(new Intent(this, notifyService.class));
startService(new Intent(notifyService.class.getName()));
//startService(new Intent(TweetCollectorService.class.getName()));
/* FROM GOOGLE */
void doBindService() {
// Establish a connection with the service. We use an explicit
// class name because we want a specific service implementation that
// we know will be running in our own process (and thus won't be
// supporting component replacement by other applications).
this.bindService(new Intent(this, updateService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}
void doUnbindService() {
if (mIsBound) {
// Detach our existing connection.
unbindService(mConnection);
mIsBound = false;
}
}
/* END OF GOOGLE CODE */
@Override
public void onDestroy() {
web.close();
doUnbindService(); // Added to `onDestroy` - suggested by Google page
super.onDestroy();
Log.v("NOTICE", "PROGRAM TERMINATED");
}
}
答案 0 :(得分:3)
我没有看到您的客户绑定到您的服务的任何地方。看看local service example.。即使调用startService也使用绑定模式的原因是因为startService调用是异步的。您需要进行额外调用以绑定服务,以确保在启动完成后收到回调。
我发现client中提供了一个非常好的服务service和NPR Open Source App示例供您学习!