![]() |
谦虚好学的跑步机 · microservices - Can ...· 1 年前 · |
![]() |
慷慨的高山 · #给自己发个博士招生广告#//长期有效 - 知乎· 1 年前 · |
![]() |
博学的领带 · python获取post参数-掘金· 2 年前 · |
![]() |
神勇威武的苦咖啡 · python 3.x - When ...· 2 年前 · |
我试图停止作为前台服务运行的服务。
当前的问题是,当我调用
stopService()
时,通知仍然保持不变。
因此,在我的解决方案中,我添加了一个接收器,我在
onCreate()
中注册它
在
onReceive()
方法中,我调用
stopforeground(true)
,它隐藏通知。然后
stopself()
停止服务。
在
onDestroy()
内部,我取消了接收器的注册。
有更合适的方法来处理这件事吗?因为stopService()根本无法工作。
@Override
public void onDestroy(){
unregisterReceiver(receiver);
super.onDestroy();
}
发布于 2013-12-31 12:22:58
startService(intent)
并传递一些数据,表示
停止服务
的键。
stopForeground(true)
stopSelf()
就在后面。
发布于 2018-06-16 14:02:25
要从活动中启动和停止前台服务,请使用:
//start
Intent startIntent = new Intent(MainActivity.this, ForegroundService.class);
startIntent.setAction(Constants.ACTION.STARTFOREGROUND_ACTION);
startService(startIntent);
//stop
Intent stopIntent = new Intent(MainActivity.this, ForegroundService.class);
stopIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION);
startService(stopIntent);
在前台服务中--使用(至少)以下代码:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {
Log.i(LOG_TAG, "Received Start Foreground Intent ");
// your start service code
else if (intent.getAction().equals( Constants.ACTION.STOPFOREGROUND_ACTION)) {
Log.i(LOG_TAG, "Received Stop Foreground Intent");
//your end servce code
stopForeground(true);
stopSelfResult(startId);
return START_STICKY;
![]() |
谦虚好学的跑步机 · microservices - Can we use server sent events in nestjs without using interval? - Stack Overflow 1 年前 |
![]() |
慷慨的高山 · #给自己发个博士招生广告#//长期有效 - 知乎 1 年前 |
![]() |
博学的领带 · python获取post参数-掘金 2 年前 |