- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为体育网络服务编写某种后台实时报价应用程序......我希望我的应用程序能够始终调用 TIME_TICK。
顺便说一句:我也尝试过使用AlarmManager,但问题是一样的。
但现在我的问题...
我使用带有服务的接收器作为执行部分。注册后每分钟都会正确调用接收器。但每天晚上服务都会终止,并且永远不会再被调用。
在 Android 2.x 上一切正常,但 Android 4.x 每天都会停止接收器...是否有可能让应用程序在 Android 4.x 上保持 Activity 状态?
接收者已在我的主要 Activity 中注册:
registerReceiver(new MyReceiver(), new IntentFilter(Intent.ACTION_TIME_TICK));
list 条目:
<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);
}
}
}
最佳答案
I also tried to use the AlarmManager, but the problem is the same
AlarmManager
是一个比 ACTION_TIME_TICK
更好的答案,特别是如果您让用户配置轮询频率(包括“请不要轮询,因为我希望电池和带宽使用量保持在较低水平”的选项)。
请随时就您认为遇到的任何问题提出单独的 StackOverflow 问题。
But every night the service is terminated and will never be called again
Android 可以并且将会在任何时候终止您的进程,无论是应用户请求还是由于老化。
Manifest-entries:
<receiver>
毫无意义,如 you cannot register for ACTION_TIME_TICK
via the manifest .
关于java - BroadcastReceiver (TIME_TICK) 每晚都会死掉?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19224905/
我的应用程序无法在 Android 7 上运行。调用了我的 BroadcastReceiver.onReceive 方法,但缺少 intent.getExtras 的内容。我已验证数据已正确加载。这是
我认为即使我退出应用程序,BroadcastReceiver AlarmManagerBroadcastReceiver 也会继续运行。我认为 BroadcastReceiver 会在我重新启动系统时
我为 Wi-Fi 创建了一个 brodcastReceiver,一切正常,除了,当我午餐应用程序时,broadcastreceiver 开始直接扫描,我无法停止它,即使我离开应用。我试图从主要 Act
我最近开始在我的 Android 应用程序上使用 Google Analytics(分析)。我想知道如何在 BroadcastReceiver 的 onReceive 方法中将事件发送到 GA。这是一
我想在 Broadcast Receiver 中检查互联网连接;并将结果( bool 标志)设置为全局变量,以便在 if 条件下将其用于整个应用程序;如果互联网断开连接,则在主要 Activity 中
如果用户向上或向下按下音量键,是否可以在我的广播接收器中检测到它?我需要完整的代码。 这是我的 Intent 过滤器 IntentFilter filter = new IntentFilter();
我正在尝试编写一个应用程序,其中我根据使用 gcm 推送通知发送的消息对 UI 进行更改,并且我设法通过使用 BroadcastReceiver onReceive 函数来实现它来实现它,但它仅在应用
我正在尝试使用 AlarmManager 安排通知当我安排一个通知时它工作得很好,但是当我安排两个通知时,第一个通知没问题,但第二个通知不起作用。 我发现几分钟后打开应用程序会通知第二个通知。我认为我
我正在阅读指南 here关于设置 BroadcastReceiver 来检查电池变化。它指出我可以像这样设置一个 BroadcastReceiver:
我想在应用程序中接收有关启用/禁用位置提供程序的信息,例如NETWORK、GPS等。我创建了简单的BroadcastReceiver: public class TestReciver extends
我正在使用广播接收器来设置警报警报,但由于某种原因它无法工作。 public class SimpleSleepActivity extends Activity { /** Called when
当我的应用程序处于后台时,我尝试播放一些音调,并按下“相机”按钮,因为我正在执行此简单的步骤。 创建BroadcastReceiver类 public class CameraButtonListen
我创建了我的广播接收器 AnprEventReciever,它应该在连接状态发生变化时被触发,但它并没有。 事件接收者: import android.content.BroadcastReceive
我有一个时间选择器来设置闹钟 public class TimePickerFragment : DialogFragment, TimePickerDialog.IOnTimeSetListener
我目前正在开发一个使用 broadcastreceiver 来检查收到的短信的应用程序,但突然间它似乎停止工作了,我什至写了一个小的测试应用程序,以至少对我来说,语法上似乎是正确的,但也不起作用。 这
我正在尝试使用 BroadcastReceiver 获取互联网连接状态。 接收类是这样的: public class ConnectivityReceiver extends BroadcastRec
我有一个小部件,它只使用服务来更新小部件的 RemoteView 的外观。该服务基于由不同注册的 BroadcastReceiver 提供的过滤器启动。当满足其中一个条件时,将调用我的 Broadca
我没有时间玩接收器,而且我对2.3.x以上的东西都不熟悉,所以当我读到这个问题时,我感到非常困惑: Can BroadcastReceiver registered in AndroidManifes
我有一个录音机 android 线程,我需要知道录音时麦克风/耳机是否已连接,所以我需要在线程内使用 BroadcastReceiver()。我如何注册它? this.registerReceiver
大家好,感谢您的帮助!我将从代码开始 所以,带有广播接收器的类是这样的: public class MyService extends Service { // ... // ACTI
我是一名优秀的程序员,十分优秀!