[英]How do I display the same activity when clicking a notification?
我正在開發音樂播放器,但是當我單擊創建的通知時,將顯示此活動的新版本,而不是顯示當前正在播放的歌曲和搜索欄的版本。
我用於通知的當前代碼是
Intent i = new Intent(this, AmplitudeMusicPlayer.class);
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(this, 0 , i, 0);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder noti = new NotificationCompat.Builder(this);
noti.setContentTitle("Now Playing")
.setContentText(songTitle)
.setSmallIcon(R.drawable.default_art)
.setContentIntent(pIntent);
notificationManager.notify(0, noti.build());
您要為活動聲明哪種啟動模式?
http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
“標准”和“ singleTop”模式在一個方面彼此不同:每次有一個新的“標准”活動意圖時,都會創建一個新的類實例來響應該意圖。 每個實例都處理一個意圖。 類似地,還可以創建“ singleTop”活動的新實例來處理新意圖。 但是,如果目標任務在其堆棧的頂部已經具有該活動的現有實例,則該實例將收到新的意圖(在onNewIntent()調用中); 沒有創建新實例。 在其他情況下(例如,如果“ singleTop”活動的現有實例在目標任務中,但不在堆棧的頂部,或者如果它在堆棧的頂部,但不在目標任務的頂部)新實例將被創建並壓入堆棧。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.