對於對話框將顯示在同一屏幕的用戶,你介紹一個Theme.Dialog主題活動,與待處理的意圖給你通知它添加it'l最好套件上建設者。像:
// This sets the pending intent that should be fired when the user clicks the
// notification. Clicking the notification launches a new activity.
Intent intent = new Intent(this, YourDialogActivity.class);
//set flags according to your implementation
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_HISTORY);
// startActivity(intent);
// Because clicking the notification launches a new ("special") activity,
// there's no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_ONE_SHOT //also check the flags here
);
mBuilder.setContentIntent(resultPendingIntent);
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(integerHere, mBuilder.build());
在你的清單,其主題對話框中添加你的活動:
<activity
android:name="com.package.YourDialogActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog" />
,具體實施,請參閱:Define the Notification's Action
這樣一來,你就不會調用在MainActivity您的應用程序和DialogActivity將只打開應用程序,並在最小化應用程序時最後打開的活動中顯示對話框。
然後在'Notification'中將'Page Position'設置爲'Pending Intent',並在'mainActivity'和載入頁面上獲取這個值,就像在'View Pager'中的那個位置一樣。 –