stopService并停止获取消息

问题描述 投票:0回答:1

我想停止我的服务并停止获取数据到我在活动中的ma处理程序。服务我连接到USB并从此端口获取数据。

我尝试这样做:

usbService.stopSelf();
Intent intent = new Intent(MainMenu.this, UsbService.class);
usbService.stopService(intent);

但是我一直有来自服务的数据。

我就像这样开始我的服务:

private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {
if (!UsbService.SERVICE_CONNECTED) {
Intent startService = new Intent(this, service);
if (extras != null && !extras.isEmpty()) {
Set<String> keys = extras.keySet();
for (String key : keys) {
String extra = extras.getString(key);
startService.putExtra(key, extra);
}
}
startService(startService);
}
Intent bindingIntent = new Intent(this, service);
bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}
java android android-service
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.