Android: How can I get the current foreground activity (from a service)?

前端 未结 12 1799
北恋
北恋 2020-11-22 07:53

Is there a native android way to get a reference to the currently running Activity from a service?

I have a service running on the background, and I would like to up

12条回答
  •  有刺的猬
    2020-11-22 08:41

    Just recently found out about this. With apis as:

    • minSdkVersion 19
    • targetSdkVersion 26

      ActivityManager.getCurrentActivity(context)

    Hope this is of any use.

提交回复
热议问题