-1

I need to Post my current location from my Android app at regular intervals (say every 5 min), while my app is in the background.

What is the component that i should use to implement the above ..in Android Native ?

MainakChoudhury
  • 502
  • 1
  • 7
  • 23

1 Answers1

0

Create a Service to send your information to your server. Presumably, you've got that under control.

Your Service should be started by an alarm triggered by the AlarmManager, where you can specify an interval. Unless you have to report your data exactly every 5 minutes, you probably want the inexact alarm so you can save some battery life.

Finally, you can register your app to get the bootup broadcast by setting up a BroadcastReceiver like so:

public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {  
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            // Register your reporting alarms here.            
        }
    }
}

You'll need to add the following permission to your AndroidManifest.xml for that to work. Don't forget to register your alarms when you run the app normally, or they'll only be registered when the device boots up.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Rahul
  • 3,293
  • 2
  • 31
  • 43