Is there an onBackPressed() alternative for a service?

后端 未结 2 1577
执念已碎
执念已碎 2021-02-14 13:30

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

相关标签:
2条回答
  • 2021-02-14 14:18

    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.

    0 讨论(0)
  • 2021-02-14 14:34

    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.

    0 讨论(0)
提交回复
热议问题