BroadcastReceiver的(TIME_TICK)死了,每天晚上? [英] BroadcastReceiver (TIME_TICK) dies every night?

查看:351
本文介绍了BroadcastReceiver的(TIME_TICK)死了,每天晚上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写某种背景实时股票应用程序运动,网络服务... 我想我的应用程序可以调用TIME_TICK所有的时间。

顺便说一句:我也尝试过使用AlarmManager,但问题是一样的。

但现在我的问题...

我用一个接收器与用于执行部的服务。 该接收器被称为寄存器后,正确的每一分钟。 但是每天晚上的服务被终止,并且将永远不会被再次调用。

在Android 2.x的一切工作正常而Android 4.x版每天都会停止接收器... 有没有posibility以保持应用程序活着在Android 4.x的?

的Reveiver注册在我的主要活动:

  registerReceiver(新MyReceiver(),新的IntentFilter(Intent.ACTION_TIME_TICK));
 

清单-项:

 <服务机器人:名称=de.pepdev.MyService/>
<接收器的Andr​​oid版本:NAME =de.pepdev.MyReceiver>
    <意向滤光器>
        <作用机器人:名称=android.intent.action.TIME_TICK/>
    &所述; /意图滤光器>
< /接收器>
 

接收器类:

 公共类MyReceiver扩展的BroadcastReceiver
{
    公共静态长nextExecTime = 0;
    公共静态日历currentTime的= Calendar.getInstance();

    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图)
    {
        currentTime的= Calendar.getInstance();

        如果(nextExecTime&其中; = currentTime.getTimeInMillis())
        {
            意向书的服务=新的意图(背景下,MyService.class);
            context.startService(服务);
        }
    }
}
 

解决方案
  

我也试过用AlarmManager,但问题是一样的。

AlarmManager 是一个比远远更好的答案 ACTION_TIME_TICK ,特别是如果你让用户配置轮询频率(包括对于选择永不查询,请,因为我喜欢我的电池和带宽的使用留低)。

请随意询问有关独立的StackOverflow问题,什么问题你觉得你正在经历吧。

  

不过,每天晚上该服务被终止,并且永远不再叫

机器人能够而且将会终止你的进程在任何时候,无论是按用户要求或因年老。

  

清单-项:

<接收器> 是没有意义的,为的您无法通过清单注册 ACTION_TIME_TICK

I want to write some kind of background-live-ticker app for sports-web-services... I would like my app to be able to call the TIME_TICK all the time.

Btw: I also tried to use the AlarmManager, but the problem is the same.

But now my problem...

I use a Receiver with a Service for the execution part. The Receiver is called every minute correctly after register. But every night the service is terminated and will never be called again.

On Android 2.x everything works fine but Android 4.x will stop the Receiver every day... Is there any posibility to keep the app alive on Android 4.x?

The Reveiver is registered in my Main-Activity:

registerReceiver(new MyReceiver(), new IntentFilter(Intent.ACTION_TIME_TICK));

Manifest-entries:

<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>

Receiver-class:

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);
        }
    }
}

解决方案

I also tried to use the AlarmManager, but the problem is the same

AlarmManager is a far better answer than ACTION_TIME_TICK, particularly if you let the user configure the polling frequency (including an option for "never poll, please, as I like my battery and bandwidth usage to stay low").

Please feel free to ask a separate StackOverflow question regarding whatever problems you feel your are experiencing with it.

But every night the service is terminated and will never be called again

Android can and will terminate your process at any point, either by user request or due to old age.

Manifest-entries:

The <receiver> is pointless, as you cannot register for ACTION_TIME_TICK via the manifest.

这篇关于BroadcastReceiver的(TIME_TICK)死了,每天晚上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆