 |
|
อยากให้ timer ทำงานตลอด และการทำงานจะมีในส่วนของการนำทางโดย google maps แม้กระทั่งดับหน้าจอ(sleep mode) แต่อยากให้ timer หยุดทำงานเมื่อกดปุ่มออกจากระบบ แต่ปุ่มออกจากระบบ กับ ตัวโค๊ดด้านล่างอยู่คนละหน้ากันอ่าคะ มีวิธีแก้ไหมคะ ขอบคุณล่วงหน้าคะ
Code (Java)
timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
double lat = gps.getLatitude();
double lng = gps.getLongitude();
try {
Connection con = connectionClass.CONN();
String query = "INSERT INTO dbo.Tracking (Latitude, Longitude, Date, SpeedKmH ) VALUES ('" + lat + "','" + lng + "', CURRENT_TIMESTAMP, '" + mySpeed + "' )";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, 0, 5000);
Tag : Mobile, JavaScript, Android, JAVA, Mobile
|
|
 |
 |
 |
 |
Date :
2016-10-18 15:09:42 |
By :
aummyasia |
View :
1205 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |