Broadcast Receiver Constantly Restarting
I'm making a widget which I want to update every second (It's like a
countdown/timer widget), so I'm using a AlarmManager and a broadcast
reciever to achieve this without waking the phone and using up all the
battery, but I keep getting a constant stream of errors in LogCat when
running the widget:
08-18 18:40:43.368 390-1988/system_process I/ActivityManager: Process
com.dysign.livetubecountdown (pid 9784) has died.
08-18 18:40:44.282 390-414/system_process I/ActivityManager: Start
proc com.dysign.livetubecountdown for broadcast
com.dysign.livetubecountdown/.WidgetAlarmManager: pid=9809 uid=10144
gids={50144, 3003, 1028}
08-18 18:40:44.306 9809-9809/com.dysign.livetubecountdown E/Trace:
error opening trace file: No such file or directory (2)
As you can see, the process keeps on dying and then restarting, this
happens when the phone is both awake and asleep.
Here is how I am starting the AlarmManager (This is inside the widget
provider class):
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
AlarmManager
am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, WidgetAlarmManager.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
am.setRepeating(AlarmManager.RTC, System.currentTimeMillis() + 1000,
1000 , pi);
}
And this is the Broadcast Receiver code:
@Override
public void onReceive(Context context, Intent intent) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_main);
DateFormat format =
SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM,
Locale.getDefault());
remoteViews.setTextViewText(R.id.widgetTextView, "TIME = " +
format.format(new Date()));
ComponentName thisWidget = new ComponentName(context, Widget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(thisWidget, remoteViews);
}
Any help would be much appreciated, thank you, SO!
No comments:
Post a Comment