0
所以我写了一些代码,以节省在无线网络上花费的时间。除了时间没有正确保存,我几乎在那里。日历问题,不保存日期
该对象接收广播,之后检查它是否连接到wifi AP。它在连接的时刻获取Date对象。断开连接后,获取连接中断的日期。
然而,当它记录的开始和结束日期似乎总是得到当前的日期,也为起始对象:
private Date startDate;
private Date stopDate;
@Override
public void onReceive(Context context, Intent intent) {
if (isOnline(context)) {
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
android.net.wifi.WifiInfo wifiInfo = wifiManager
.getConnectionInfo();
Log.d("WIFI:", "IN FIRST IF, SO CONNECTED");
if (wifiInfo.getSupplicantState() == (SupplicantState.COMPLETED)) {
Calendar c = Calendar.getInstance();
this.startDate = c.getTime();
this.initialConnection = true;
}
} else if (this.initialConnection) {
Calendar d = Calendar.getInstance();
this.stopDate = d.getTime();
//problem persists here
String s = "TIME:" + d.getTime().toString() + " started at:"
+ startDate.toString() + "stopped at"
+ this.stopDate.toString();
Log.d("WIFI:", s);
this.initialConnection = false;
}
}
输出
D/WIFI: ( 684): TIME:Mon Mar 12 13:18:16 GMT+02:00 2012 started at:Mon Mar 12 13:18:16 GMT+02:00 2012stopped atMon Mar 12 13:18:16 GMT+02:00 2012
是我的开始时间获取当前时间再次提到它时?我怎样才能让它保存startTime?