服务:如果开始bindService onTaskRemoved不叫 [英] Service: onTaskRemoved not called if started with bindService

查看:2818
本文介绍了服务:如果开始bindService onTaskRemoved不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个服务已onTaskRemoved()方法来实现。结果
当服务开始与startService()onTaskRemoved()调用的时候,应用程序通过刷卡近期-应用-列表中删除。结果
但是,如果该服务开始bindService(),然后onTaskRemoved()从来没有所谓的。搜索结果
如何使服务调用onTaskRemoved()时,应用程序通过刷卡最近-应用程序列表中删除它已经开始与bindService()?

以下方法调用,如果开始的:

  1。 bindService():
活动:的onCreate()
CustomService:的onCreate()
CustomService:调用onStart()
CustomService:onStartCommand()
CustomService:onBind()
//这里我们刷卡,从应用程序中删除最近-应用程序列表
CustomService:onTrimMemory()2. startService():
ActivityA:的onCreate()
CustomService:的onCreate()
CustomService:调用onStart()
CustomService:onStartCommand()
CustomService:onBind()
//刷卡从最近-应用程序列表中删除应用程序
CustomService:onTrimMemory()
CustomService:onTaskRemoved()//< =====
CustomService:onUnbind()


解决方案

一个服务可以绑定或启动或两者兼而有之。这取决于你如何实现 onStartCommand onBind 说的文档。

<一个href=\"http://developer.android.com/guide/components/services.html\">http://developer.android.com/guide/components/services.html

但是,如果你希望你的服务做的都停留在和超过一个IBinder与客户交谈,然后只需启动该服务,然后绑定到它。

  startService(新意图(背景下,CustomerService.class));
//绑定到服务
bindService(新意图(背景下,CustomerService.class)
                        mConnection,Context.BIND_AUTO_CREATE);

A Service has onTaskRemoved() method implemented.
When the service started with startService() onTaskRemoved() called when the app removed from recent-apps-list by swipe.
But if the service started with bindService(), then onTaskRemoved() never called.

How to make Service call onTaskRemoved() when app removed from recent-apps-list by swipe after it has been started with bindService()?

Following methods called if started with:

1. bindService():
Activity﹕ onCreate()
CustomService﹕ onCreate()
CustomService﹕ onStart()
CustomService﹕ onStartCommand()
CustomService﹕ onBind()
// Here we swipe to remove app from recent-apps-list
CustomService﹕ onTrimMemory()

2. startService():
ActivityA﹕ onCreate()
CustomService﹕ onCreate()
CustomService﹕ onStart()
CustomService﹕ onStartCommand()
CustomService﹕ onBind()
// Swipe to remove app from recent-apps-list
CustomService﹕ onTrimMemory()
CustomService﹕ onTaskRemoved() // <===== 
CustomService﹕ onUnbind()

解决方案

A service can be bound or started or both. It depends on how you implement onStartCommand and onBind say the docs.

http://developer.android.com/guide/components/services.html

But if you want your service to do both stay around and talk with clients over an IBinder then simply start the service and then bind to it.

startService(new Intent(context, CustomerService.class));
// Bind to the service
bindService(new Intent(context, CustomerService.class),
                        mConnection, Context.BIND_AUTO_CREATE);

这篇关于服务:如果开始bindService onTaskRemoved不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆