Tuesday, August 26, 2014

Prioritizing Background Services

Moving a service to the foreground

int NOTIFICATION_ID = 1;
Intent intent = new Intent(this, MyActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 1, intent, 0));

Notification notification = new Notification(R.drawable.icon, "Running in the Foreground", System.currentTimeMillis());
notification.setLatestEventInfo(this, "Title", "Text", pi);
notification.flags = notification.flags |
Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, notification);

Moving a service to the background

// Move to the background and remove the Notification
stopForeground(true);

No comments:

Post a Comment