Skip to content

Instantly share code, notes, and snippets.

@wangerekaharun
Last active January 10, 2018 10:25
Show Gist options
  • Save wangerekaharun/79529502114466fe8b3fb63f5624d605 to your computer and use it in GitHub Desktop.
Save wangerekaharun/79529502114466fe8b3fb63f5624d605 to your computer and use it in GitHub Desktop.
Intent Service class which sends a broadcast after every 15 minutes
public class BackgroundService extends IntentService {
public static final String ACTION="ke.co.appslab.androidbackgroundservices.Receivers.ResponseBroadcastReceiver";
// Must create a default constructor
public BackgroundService() {
// Used to name the worker thread, important only for debugging.
super("backgroundService");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
// This describes what will happen when service is triggered
Log.i("backgroundService","Service running");
//create a broadcast to send the toast message
Intent toastIntent= new Intent(ACTION);
toastIntent.putExtra("toastMessage","I'm running after ever 15 minutes");
sendBroadcast(toastIntent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment