Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 05759d15 authored by Scott Main's avatar Scott Main Committed by Android (Google) Code Review
Browse files

Merge "add notice to not use 0 in startForeground(). also delete some obsolete...

Merge "add notice to not use 0 in startForeground(). also delete some obsolete back-compat tips for <=donut bug: 8746126" into jb-mr2-dev
parents 2787ba25 2e6de8fd
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -633,7 +633,7 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac
     * 
     * 
     * @param id The identifier for this notification as per
     * @param id The identifier for this notification as per
     * {@link NotificationManager#notify(int, Notification)
     * {@link NotificationManager#notify(int, Notification)
     * NotificationManager.notify(int, Notification)}.
     * NotificationManager.notify(int, Notification)}; must not be 0.
     * @param notification The Notification to be displayed.
     * @param notification The Notification to be displayed.
     * 
     * 
     * @see #stopForeground(boolean)
     * @see #stopForeground(boolean)
+4 −22
Original line number Original line Diff line number Diff line
@@ -252,19 +252,6 @@ document.</p>


<h2 id="CreatingStartedService">Creating a Started Service</h2>
<h2 id="CreatingStartedService">Creating a Started Service</h2>


<div class="sidebox-wrapper">
<div class="sidebox">
  <h2>Targeting Android 1.6 or lower</h2>
  <p>If you're building an application for Android 1.6 or lower, you need
to implement {@link android.app.Service#onStart onStart()}, instead of {@link
android.app.Service#onStartCommand onStartCommand()} (in Android 2.0,
{@link android.app.Service#onStart onStart()} was deprecated in favor of {@link
android.app.Service#onStartCommand onStartCommand()}).</p>
  <p>For more information about providing compatibility with versions of Android older than 2.0, see
the {@link android.app.Service#onStartCommand onStartCommand()} documentation.</p>
</div>
</div>

<p>A started service is one that another component starts by calling {@link
<p>A started service is one that another component starts by calling {@link
android.content.Context#startService startService()}, resulting in a call to the service's
android.content.Context#startService startService()}, resulting in a call to the service's
{@link android.app.Service#onStartCommand onStartCommand()} method.</p>
{@link android.app.Service#onStartCommand onStartCommand()} method.</p>
@@ -687,9 +674,12 @@ Intent notificationIntent = new Intent(this, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.notification_title),
notification.setLatestEventInfo(this, getText(R.string.notification_title),
        getText(R.string.notification_message), pendingIntent);
        getText(R.string.notification_message), pendingIntent);
startForeground(ONGOING_NOTIFICATION, notification);
startForeground(ONGOING_NOTIFICATION_ID, notification);
</pre>
</pre>


<p class="caution"><strong>Caution:</strong> The integer ID you give to {@link
android.app.Service#startForeground startForeground()} must not be 0.</p>



<p>To remove the service from the foreground, call {@link
<p>To remove the service from the foreground, call {@link
android.app.Service#stopForeground stopForeground()}. This method takes a boolean, indicating
android.app.Service#stopForeground stopForeground()}. This method takes a boolean, indicating
@@ -697,14 +687,6 @@ whether to remove the status bar notification as well. This method does <em>not<
service. However, if you stop the service while it's still running in the foreground, then the
service. However, if you stop the service while it's still running in the foreground, then the
notification is also removed.</p>
notification is also removed.</p>


<p class="note"><strong>Note:</strong> The methods {@link
android.app.Service#startForeground startForeground()} and {@link
android.app.Service#stopForeground stopForeground()} were introduced in Android 2.0 (API Level
5). In order to run your service in the foreground on older versions of the platform, you must
use the previous {@code setForeground()} method&mdash;see the {@link
android.app.Service#startForeground startForeground()} documentation for information about how
to provide backward compatibility.</p>

<p>For more information about notifications, see <a
<p>For more information about notifications, see <a
href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Creating Status Bar
href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Creating Status Bar
Notifications</a>.</p>
Notifications</a>.</p>