Saturday, March 8, 2014

AlarmManager regularly updated desktop clock, how time synchronization with the system. .


I want to learn to do a digital version of Desktop Clock Widget, the Internet also could not find a reference to the source code, CSDN in to download one, analog clock, using AnalogClock the system components, but also irrelevant.

I do not know how to start, and finally with the AlarmManager to update regularly, but the problem is not synchronized with the system time, active heroes can give me a code or guidance about the younger. . . Thanks. . .

xu0013@163.com<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Nobody yet. . .
Reply:
You can engage in a Broadcast receiver, try to listen what ACTION_TIME_TICK, should receive every minute or so. Similar AlarmManagerService code inside:
 
IntentFilter filter = new IntentFilter ();
filter.addAction (Intent.ACTION_TIME_TICK);
filter.addAction (Intent.ACTION_DATE_CHANGED);
mContext.registerReceiver (this, filter);

Reply:
Forgot to say to get the current time in onReceive () action in a similar System.currentTimeMillis () call can be.
Reply:
reference to the second floor of the reply:
you can engage in a Broadcast receiver, try to listen what ACTION_TIME_TICK, should receive every minute or so. Similar AlarmManagerService code inside:

Java code


IntentFilter filter = new IntentFilter ();
filter.addAction (Intent.ACTION_TIME_TICK);
filter.a ......



Ah, but you said this method has been tried before me, and in the Activity inside registerReceiver no problem, can receive Intent.ACTION_TIME_TICK broadcasting system per minute; derived classes inside context.registerReceiver in AppWidgetProvider of an error. . .

Error saying Unable to start receiver. . . Somehow. . . Yeah do not understand. . . Seeking help. . .
Reply:
Their top. . .
Reply:
Oh know where the problem lies. . .
AppWidgetProvider class that several callback methods with a context parameter, but the context of context with the Activity bit different, had it. . .

 
context.getApplicationContext (). registerReceiver (..., ...)

Reply:
context.getApplicationContext () registerReceiver (..., ...);.
After that, how write off this ACTION_TIME_TICK radio?
Reply:
I call context.getApplicationContext in onDisabled () unregisterReceiver (mBroadcastReceiver);.
Error

No comments:

Post a Comment