I'm currently developing an application and I'm using this post code to get the GPS lock. What is the simplest and most robust way to get the user's current location on Android?
It works like a charm! It chooses very well for my requirements. What I'm now trying to do is triggering this method every 10 minutes to get gps signal and saving it in a txt file. My problem is I've been unable to understand how AlarmManager works as it calls AFAIK the onCreate() method of the activity. How can I make an AlarmManager call an specific method every 10 minutes in the background even with the telephone sleeping?
Edit 2: I've used the code provided by A--C but for some reason the alarm isn't calling the method on my class AlarmBroadcastReceiver. This is my method in the MainActivity.
Intent intent = new Intent (this, AlarmBroadcastReceiver.class);
PendingIntent pendIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService (Context.ALARM_SERVICE);
alarmManager.cancel(pendIntent); //cancel if active already
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis()+4000,
4000, pendIntent);
and in the AlarmBroadcastReceiver class.
public class AlarmBroadcastReceiver extends BroadcastReceiver{
public float accuracy;
public double latitude;
public double longitud;
public static boolean Activado=false;
public void onReceive(Context context, Intent intent) {
Log.d("AlarmManager", "Method onReceiveCalled");
}
What I'm doing wrong?