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

前端 未结 12 2019
北恋
北恋 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:17

    I don't know if it's a stupid answer, but resolved this problem by storing a flag in shared preferences every time I entered onCreate() of any activity, then I used the value from shered preferences to find out what it's the foreground activity.

提交回复
热议问题