How to detect when an Android app goes to the background and come back to the foreground

后端 未结 30 1377
独厮守ぢ
独厮守ぢ 2020-11-22 00:56

I am trying to write an app that does something specific when it is brought back to the foreground after some amount of time. Is there a way to detect when an app is sent to

30条回答
  •  别那么骄傲
    2020-11-22 01:16

    ActivityLifecycleCallbacks might be of interest, but it isn't well documented.

    Though, if you call registerActivityLifecycleCallbacks() you should be able to get callbacks for when Activities are created, destroyed, etc. You can call getComponentName() for the Activity.

提交回复
热议问题