最佳答案
鉴于您自己提供了答案,我不确定您是否还在寻找答案.但是,如果您希望实现原始目标,则可能需要
原文链接:https://www.f2er.com/android/430814.html>每当时间发生变化时重建RemoteView(它更容易)
>设置BroadcastReceiver以捕获时钟的滴答,以便您知道时间何时发生变化.
所以,有些代码有点像这样:
class MyCleverThing extends Service (say) {
// Your stuff here
private static IntentFilter timeChangeIntentFilter;
static {
timeChangeIntentFilter = new IntentFilter();
timeChangeIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
timeChangeIntentFilter.addAction(Intent.ACTION_TIME_CHANGED);
}
// Somewhere in onCreate or equivalent to set up the receiver
registerReceiver(timeChangedReceiver,timeChangeIntentFilter);
// The actual receiver
private final BroadcastReceiver timeChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context,Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_TIME_CHANGED) ||
action.equals(Intent.ACTION_TIMEZONE_CHANGED))
{
updateWidgets(); // Your code to rebuild the remoteViews or whatever
}
}
};