[英]Recreating activity with getting a notification
There is the following task: 有以下任务:
There is the first activity (for example, "Activity A"), and the second activity ("Activity B"). 有第一个活动(例如“活动A”)和第二个活动(“活动B”)。 Also there is some Service (just "Service) for catching notifications from my server. I'd like to realize the following algorithm: 另外,还有一些服务(简称“服务”)用于捕获来自服务器的通知。我想实现以下算法:
I've made all steps without the third one, because I don't know how I can get the current activity. 我已完成所有步骤而没有第三步,因为我不知道如何获得当前活动。 Please, tell me, is there any way to detect which activity is current? 请告诉我,有什么方法可以检测到当前正在进行的活动吗? Thanks. 谢谢。
There is no "legit" way of getting the Activity
the user is on. 没有“合法”的方式来获取用户处于Activity
状态。
You can always do a hack : 您可以随时进行破解:
static boolean sVisible
member in your ActivityB
class 在ActivityB
类中声明一个static boolean sVisible
成员 onStart()
, set that flag to true
在onStart()
,将该标志设置为true
onStop()
, set that flag to false
在onStop()
,将该标志设置为false
Service
check if(ActivityB.sVisible)
在您的Service
检查if(ActivityB.sVisible)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.