Is there an onBackPressed() alternative for a service?

泄露秘密 提交于 2019-12-03 11:58:26

It is probably done using system alert windows - so the service creates and manages a window that is added to the window manager, which has a custom callback set on it.

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.

remember to add permission

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

and add your service class

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

in AndroidManifest.xml.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!