Global class to register listeners for all the activities in android

后端 未结 3 810
日久生厌
日久生厌 2020-12-22 10:00

I have two Activity classes. Activity A and Activity B. Later on I added Activity C which gets launched when user shakes the device be

相关标签:
3条回答
  • 2020-12-22 10:09

    Create a main activity class which will be extended by Activity A, B and C. You can register your ShakeListener in this main activity.

    0 讨论(0)
  • 2020-12-22 10:20

    You can define your own ActivityStack in Application class, properly manage by adding and removing activities. Finally refer to this stack from activity C.

    There is example how ActivityStack works: Back Stack Example

    0 讨论(0)
  • 2020-12-22 10:23

    In your case, you need to implement a Service to listen to sensors in the background. Go through documentation:Service

    You cannot just use Broadcastreceiver to accomplish this task.

    Reference:

    Android sensor listening when app in background

    Refer this link for help: http://code.tutsplus.com/tutorials/android-barometer-logger-acquiring-sensor-data--mobile-10558

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