我寫了一個通知函數發送notificaiton,它會切換到規定的活動,當用戶點擊頂欄上的通知。我的代碼做了我想要的。但有一個問題。通知和主頁按鈕
假設有3個活動(A,B,C)和它扔掉切換到A時用戶點擊頂部欄上的通知。
的流程爲:
(1)用戶打開
(2)點擊在A處的按鈕和開關向B
(3)點擊頂部欄
(4)切換到該通知(這是細)
(5)同樣,在A處點擊一個按鈕,切換到B
(6)按主頁按鈕來隱藏應用
(7)長按主頁按鈕並單擊應用圖標
(8)切換到A(???它應該切換到B,因爲我在活動B!)
----我怎樣才能避免它切換到活動A,當我長按主頁按鈕切換到我的應用程序?謝謝!
這裏是代碼片段:
int notificationCounter = 0;
private void displayNotificationMessage(String title, String message, int notification_id, String fromUser, boolean vibrate, boolean playSound, String notificationActionStr)
{
if (receiverMessageBroadcast || !currentTargetUser.equals(fromUser))
{
Intent intent = new Intent();
intent.setClass(this, MainActivity.class);
//intent.setAction(notificationAction + "_" + System.currentTimeMillis());
Bundle bundle = new Bundle();
bundle.putInt("notificationAction", 1);
bundle.putString("targetUser", fromUser);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification notification = new Notification(R.drawable.notification, message, System.currentTimeMillis());
notification.setLatestEventInfo(this, title, message, PendingIntent.getActivity(this.getBaseContext(), notificationCounter, intent, PendingIntent.FLAG_UPDATE_CURRENT));
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
if (playSound)
notification.defaults |= Notification.DEFAULT_SOUND;
if (vibrate)
notification.vibrate=new long[] {100L, 100L, 200L, 500L};
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
notificationMgr.notify(fromUser, 0, notification);
notificationCounter++;
}
}
您是否正在主頁上關閉您的應用程序? – drulabs 2012-04-19 16:46:20
如果一切都失敗http://stackoverflow.com/questions/9645159/hide-android-application-in-long-press-home-button-menu – Luke 2012-04-19 16:48:14
感謝KKD這可能幫助,我希望用戶按下HOME鍵隱藏應用程序。當他們長按主頁按鈕時,他們可以用最新的活動再次打開應用程序。我的問題是它總是顯示由通知定義的Activity(哪個是錯誤的,它應該顯示最新的Activity)。 – 2012-04-20 04:23:00