create a service and start a timer like shown below.Hope this helps
public void starttimer(){
timer = new CountDownTimer(300000, 2000) {
@Override
public void onTick(long millisUntilFinished) {
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
try {
location = locationManager.getLastKnownLocation(provider);
}
catch (Exception e)
{
}
if(location==null) {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
if (location != null) {
double lat = location.getLatitude();
double longg = location.getLongitude();
mMap.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(lat,longg) , 14.0f) );
} else {
Toast.makeText(MainActivity.this, "Device Failed To Fetch Lat Long", Toast.LENGTH_LONG).show();
}
}
@Override
public void onFinish() {
//your code when timer finishes
}
}.start();
}