我对代码中date format.getDateTimeInstance().format(date)的工作感到困惑我正在执行以下操作:
BroadcastReceiver myReciever = new BroadcastReceiver(){
String currentDateTimeString;
@Override
public void onReceive(Context context, Intent intent){
currentDateTimeString = DateFormat.getDateTimeInstance().format(date);
switch(prevRAT) //somevariable
{
case 0:
det1.setText(currentDateTimeString); //det is an EditText variable
break;
case 1:
det2.setText(currentDateTimeString;
break;
default:
break;
}
}
};
控件下次进入onReceive函数时,currentDateTimeString不会更新,它显示的日期和时间值相同。我不能理解这种行为。如何获取当前时间。
最佳答案
BroadcastReceiver myReciever = new BroadcastReceiver(){
String currentDateTimeString;
@Override
public void onReceive(Context context, Intent intent){
currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
switch(prevRAT) //somevariable
{
case 0:
det1.setText(currentDateTimeString); //det is an EditText variable
break;
case 1:
det2.setText(currentDateTimeString;
break;
default:
break;
}
}
};