I have a task in which the app detects LatLng using LocationListener and adds to ArrayList every two minutes. If the ArrayList size reaches six it sends the contents to SMS and clear the items of the ArrayList. It only detects the LatLng if the device moves only. If the mobile stops before adding six elements to ArrayList then the it was incomplete. I have used the following code to send SMS if the ArrayList size reaches six.
private void sendLog() {
Toast.makeText(MainPage.this,"Sending Log",Toast.LENGTH_LONG).show();
final SharedPreferences account=getSharedPreferences("admins",MODE_PRIVATE);
String interval=account.getString("lti", "");
int timeInterval=Integer.parseInt(interval);
final List<String> loglist = new ArrayList<String>();
LocationManager logManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
logManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, timeInterval*60000, 250, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
double latitude=location.getLatitude();
double longitude=location.getLongitude();
DecimalFormat dFormat = new DecimalFormat("#.####");
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("kk:mm");
SimpleDateFormat sdf1=new SimpleDateFormat("dd-MM,yy");
String time=sdf.format(date);
final String dateLog=sdf1.format(date);
loglist.add("!+" + dFormat.format(latitude) + ",+" + dFormat.format(longitude) + "," + time);
if (loglist.size()==6) {
log = new StringBuilder();
for (int j = 0; j < loglist.size(); j++) {
log.append(loglist.get(j).toString());
}
SmsManager smsManager=SmsManager.getDefault();
smsManager.sendTextMessage(logPreferences.getString("admin1", ""), null," "+ log.toString()+"!"+dateLog+"!", null, null);
loglist.removeAll(loglist);
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
});
}
My problem is if the contents of the ArrayList not changed in next twenty minutes I have to send the incomplete ArrayList to SMS. Now how to detect the content of the ArrayList not changed for 20 minutes. Anyone knows please help. Thanks.