I am writing an Android app that retrieves the phone's current location and sends it too a webserver. I want to be able to press a start button and have the app continue to retrieve and send the location at a predetermined interval (say every 10 minutes) and then have it stop on another button press.
Here is the code for my buttons:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startButton.setOnClickListener(new OnClickListener() {
@Override
//When the button is clicked
public void onClick(View v) {
finishButton.setEnabled(true);
startButton.setEnabled(false);
//Loops every 10mins
pingCurrentLocation();
}
});
finishButton.setOnClickListener(new OnClickListener() {
@Override
//When the button is clicked
public void onClick(View v) {
startButton.setEnabled(true);
finishButton.setEnabled(false);
pingCurrentLocation();
}
});
}
pingCurrentLocation is the function that gets the location and sends it.
I know that using an AlarmManager would probably achieve what I want but I have been unable to make sense of any of it. Are there any clear steps or templates that will work in my situation.