【发布时间】:2013-10-07 12:26:58
【问题描述】:
我想为体育网络服务编写某种后台实时报价应用程序... 我希望我的应用能够一直调用 TIME_TICK。
顺便说一句:我也尝试使用AlarmManager,但问题是一样的。
但现在我的问题...
我在执行部分使用带有服务的接收器。 注册后每分钟正确调用接收器。 但是每天晚上服务都会被终止,并且永远不会再被调用。
在 Android 2.x 上一切正常,但 Android 4.x 每天都会停止接收器... 是否有任何可能让应用程序在 Android 4.x 上保持活力?
Revever 已在我的 Main-Activity 中注册:
registerReceiver(new MyReceiver(), new IntentFilter(Intent.ACTION_TIME_TICK));
清单条目:
<service android:name="de.pepdev.MyService" />
<receiver android:name="de.pepdev.MyReceiver">
<intent-filter>
<action android:name="android.intent.action.TIME_TICK" />
</intent-filter>
</receiver>
接收者等级:
public class MyReceiver extends BroadcastReceiver
{
public static long nextExecTime = 0;
public static Calendar currentTime = Calendar.getInstance();
@Override
public void onReceive(Context context, Intent intent)
{
currentTime = Calendar.getInstance();
if(nextExecTime <= currentTime.getTimeInMillis())
{
Intent service = new Intent(context, MyService.class);
context.startService(service);
}
}
}
【问题讨论】:
-
你能把日志贴在这里吗?你知道服务被终止的原因吗?
-
感谢您的帮助,但日志什么也没说。该服务被调用了几次,到晚上 logcat 没有我的应用程序的任何进一步条目。最后一个循环成功完成。像alarmmanage这样的系统消息也没有抛出任何东西。
标签: java android time broadcastreceiver alarmmanager