<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                > 編寫:[fastcome1985](https://github.com/fastcome1985) - 原文:[http://developer.android.com/training/notify-user/navigation.html](http://developer.android.com/training/notify-user/navigation.html) 部分設計一個notification的目的是為了保持用戶的導航體驗。為了詳細討論這個課題,請看 [Notifications](#) API引導,分為下列兩種主要情況: ~~~ * 常規的activity 你啟動的是你application工作流中的一部分[Activity](developer.android.com/reference/android/app/Activity.html)。 * 特定的activity 用戶只能從notification中啟動,才能看到這個[Activity](http://developer.android.com/intl/zh-cn/reference/android/app/Activity.html),在某種意義上,這個[Activity](http://developer.android.com/intl/zh-cn/reference/android/app/Activity.html)是notification的擴展,額外展示了一些notification本身難以展示的信息。 ~~~ ### 設置一個常規的[Activity](# "An activity represents a single screen with a user interface.") PendingIntent 設置一個直接啟動的入口[Activity](# "An activity represents a single screen with a user interface.")的PendingIntent,遵循以下步驟: 1 在manifest中定義你application的[Activity](# "An activity represents a single screen with a user interface.")層次,最終的manifest文件應該像這個: ~~~ <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ResultActivity" android:parentActivityName=".MainActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity"/> </activity> ~~~ 2 在基于啟動[Activity](# "An activity represents a single screen with a user interface.")的[Intent](#)中創建一個返回棧,比如: ~~~ int id = 1; ... Intent resultIntent = new Intent(this, ResultActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(ResultActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(resultIntent); // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); ... NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(id, builder.build()); ~~~ ### 設置一個特定的[Activity](# "An activity represents a single screen with a user interface.") PendingIntent 一個特定的[Activity](# "An activity represents a single screen with a user interface.")不需要一個返回棧,所以你不需要在manifest中定義[Activity](# "An activity represents a single screen with a user interface.")的層次,以及你不需要調用 [addParentStack()](#))方法去構建一個返回棧。作為代替,你需要用manifest設置[Activity](# "An activity represents a single screen with a user interface.")任務選項,以及調用 [getActivity()](#))創建[PendingIntent](#) 1. manifest中,在[Activity](# "An activity represents a single screen with a user interface.")的 [](#) 標簽中增加下列屬性:[android:name="activityclass"](#)[activity](# "An activity represents a single screen with a user interface.")的完整的類名。[android:taskAffinity=""](#)結合你在代碼里設置的[FLAG_ACTIVITY_NEW_TASK](#)標識, 確保這個[Activity](# "An activity represents a single screen with a user interface.")不會進入application的默認任務。任何與 application的默認任務有密切關系的任務都不會受到影響。[android:excludeFromRecents="true"](#)將新任務從最近列表中排除,目的是為了防止用戶不小心返回到它。 1. 建立以及發布notification:a.創建一個啟動[Activity](# "An activity represents a single screen with a user interface.")的[Intent](#).b.通過調用[setFlags()](#))方法并設置標識[FLAG_ACTIVITY_NEW_TASK](#) 與 [FLAG_ACTIVITY_CLEAR_TASK](#),來設置[Activity](# "An activity represents a single screen with a user interface.")在一個新的,空的任務中啟動。c.在[Intent](#)中設置其他你需要的選項。d.通過調用 [getActivity()](http://developer.android.com/intl/zh-cn/reference/android/app/PendingIntent.html#getActivity%28android.content.Context,%20int,%20android.content.Intent,%20int%29)方法從[Intent](#)中創建一個 [PendingIntent](#),你可以把這個[PendingIntent](#) 當做 [setContentIntent()](http://developer.android.com/intl/zh-cn/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentIntent%28android.app.PendingIntent%29)的參數來使用。下面的代碼片段演示了這個過程: ~~~ // Instantiate a Builder object. NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Creates an Intent for the Activity Intent notifyIntent = new Intent(new ComponentName(this, ResultActivity.class)); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Creates the PendingIntent PendingIntent notifyIntent = PendingIntent.getActivity( this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT ); // Puts the PendingIntent into the notification builder builder.setContentIntent(notifyIntent); // Notifications are issued by sending them to the // NotificationManager system service. NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Builds an anonymous Notification object from the builder, and // passes it to the NotificationManager mNotificationManager.notify(id, builder.build()); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看