So I\'m not sure where/how to implement this method to make my service run in the foreground. Currently I start my service by the following in another activity:
<
From your main activity, start the service with the following code:
Intent i = new Intent(context, MyService.class);
context.startService(i);
Then in your service for onCreate()
you would build your notification and set it as foreground like so:
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.app_icon)
.setContentTitle("My Awesome App")
.setContentText("Doing some work...")
.setContentIntent(pendingIntent).build();
startForeground(1337, notification);