Android 停止上次打开时创建的服务

Android 停止上次打开时创建的服务,android,service,background-process,Android,Service,Background Process,我创建了一个服务,当我的活动被销毁时启动,好的。 我关闭了我的应用程序,服务正常运行,但当我再次打开我的应用程序时,我调用了stopservice,但服务未完成 如何停止上次打开应用程序时创建的服务?这里,我放了一些对您有帮助的代码片段。您可以使用取消绑定服务停止服务 protected ServiceConnection mServerConn = new ServiceConnection() { @Override public void onServiceConnected(Compon

我创建了一个服务,当我的活动被销毁时启动,好的。 我关闭了我的应用程序,服务正常运行,但当我再次打开我的应用程序时,我调用了stopservice,但服务未完成


如何停止上次打开应用程序时创建的服务?

这里,我放了一些对您有帮助的代码片段。您可以使用取消绑定服务停止服务

protected ServiceConnection mServerConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
    Log.d(LOG_TAG, "onServiceConnected");
}

@Override
public void onServiceDisconnected(ComponentName name) {
    Log.d(LOG_TAG, "onServiceDisconnected");
}
}

}


}

请提供足够的信息以重现此问题。代码总是很好的,让你的问题更清楚!!请把你的密码贴在这里
public void start() {
// mContext is defined upper in code, I think it is not necessary to explain what is it 
mContext.bindService(i, mServerConn, Context.BIND_AUTO_CREATE);
mContext.startService(i);
public void stop() {
mContext.stopService(new Intent(mContext, ServiceRemote.class));
mContext.unbindService(mServerConn);