【发布时间】:2021-06-24 22:11:34
【问题描述】:
我在 Android Studio 中构建了一个名为 MService 扩展服务的类,我这样启动服务:- 在与按钮关联的 onClick 内部-
Intent serviceIntent = new Intent(getApplicationContext(), MService.class);
serviceIntent.putExtra("ID", "1");
startService(serviceIntent);
服务onStartCommand 方法午餐并且工作得很好..
问题是当按钮单击时我不知道如何结束服务,我尝试这样做:
stopService(new Intent(getApplicationContext(), MService.class));
在 onClick 方法中, onDestroy 午餐,但服务仍在运行
我怎样才能阻止它?
【问题讨论】:
标签: android android-studio android-intent service