Intent intent = new Intent(this, MyActivity.class); Pendinglntent pi = PendingIntent.getActivity(this, 1, intent, 0));
LISTING 9-7 (continued)
Notification notification = new Notification(R.drawable.icon,
"Running in the Foreground", System.currentTimeMillis()); notification.setLatestEventInfo(this, "Title", "Text", pi);
notification.flags = notification.flags |
Listing 9-7 uses setLatestEventInfo to update the notification using the default status window layout. Later in this chapter you'll learn how to specify a custom layout for your Notification. Using this technique you can provide more details of your ongoing Service to users.
Once your Service no longer requires foreground priority you can move it back to the background, and optionally remove the ongoing notification using the stopForeground method, as shown in Listing 9-8. The Notification will be canceled automatically if your Service stops or is terminated.
Was this article helpful?
Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.