奇巧:服务退出的主要活动后为空 [英] KitKat: Service is null after exiting main activity
问题描述
我有一个服务,我需要检查它是否是从静态上下文一段时间后仍在运行。
[我发现这只是发生在Android奇巧] 的
I have a service and I need to check if it's still running after some time from a static context. [I noticed this happens only on Android KitKat]
我做了什么:
我的服务:
public class Servizio extends Service {
public static Service servizio;
[...Other things...]
@Override
public void onCreate() {
super.onCreate();
servizio = this;
scheduleMyAlarmToDoSomethingAfterSomeTime();
}
[...Other things...]
}
然后我从主活动推出的服务中的的onCreate 的:
@Override
protected void onCreate(Bundle savedInstanceState) {
[...]
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ServizioUtility.toggleService(this, true);
[...]
}
然后我检查它是否在一分钟后是空(与报警接收器的报警器是由服务推出需要注意的是接收器工作正常,以下code叫):
Then I check if it's null after a minute (with an alarm receiver whose alarm was launched by the service. Note that the receiver works fine and the following code is called):
if (Servizio.servizio!=null) {// FIXME
[...]
//THIS IS NOT CALLED IN THE 2ND SCENARIO
}
有2情况:
- 我跑的活动,等待启动的警报和 Servizio.servizio 的不为null。
- 我跑活动,杀它使用,等待报警接收机被称为 Servizio.servizio 的是现在空。需要注意的是该服务,另一方面,仍然运行(从设置 - > APP-检查>运行菜单)。
- I run the activity, wait for the alarm to be launched and Servizio.servizio is not null.
- I run the activity, "kill" it using the , wait for the alarm receiver to be called, Servizio.servizio is now null. Note that the service, on the other hand, is still running (checked from Settings->App->Running menu).
这是怎么回事在第二个方案中?
What's happening in the 2nd scenario?
推荐答案
我发现这是与Android奇巧一个问题,如果你想看看:
I found out this is an issue with Android KitKat, if you want to check it out:
HTTPS://$c$c.google。 COM / p /安卓/问题/细节?ID = 63793
HTTPS://$c$c.google。 COM / p /安卓/问题/细节?ID = 63618
这篇关于奇巧:服务退出的主要活动后为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!