是否有一个onBack pressed()替代服务? [英] Is there an onBackPressed() alternative for a service?

查看:113
本文介绍了是否有一个onBack pressed()替代服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,服务无法实现返回键preSS和我理解的理由。但有一个应用的工具条(上Play商店),其反应返回键presses。它是增加了一个视图系统覆盖并删除时,返回键为pressed视图的服务。任何人都可以解释这是如何实现的?

I know that services cannot implement Back key press and I understand the rationale. But there is an app called SideBar (on Play Store) that reacts to back key presses. It is a service that adds a view as system overlay and removes the view when the back key is pressed. Can anybody explain how this is done?

下面是另一个应用,做它做好。我已经走遍了网络,但还没有找到一个解决这个问题。任何想法?

Here is another app that does it well. I have scoured the web, but have not found a solution to this problem. Any ideas?

推荐答案

在这里 是很好的例子,addview的服务,你也可以使用监听器,如果你想在服务。

here is nice example to addview in Service and also you can use listeners if you want in services.

我也在寻找服务听众执行,终于找到了。

i was also looking for the listeners implementation in service and finally found it.

记得加权限

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

和增加服务类

<application>
.
 .
  <service android:name=".YourServiceClass"></service>
 .
.
</application>

在AndroidManifest.xml中。

in AndroidManifest.xml.

这篇关于是否有一个onBack pressed()替代服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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