我正在制作一个音乐应用程序,它在播放音频时显示通知。单击时,此通知将通过意图打开主 (UI) 活动。
虽然这应该是一个非常简单的过程,但出于某种原因,无论我做什么,当按下通知时,主要活动总是会被破坏。我已经尝试过 singleTop、singleTask(都作为意图标志和清单值)、保存实例状态包、onNewIntent,基本上任何接近我能找到的解决方案的东西。但活动总是被破坏。我只能通过 getIntent 获取意图。
主要活动:https : //pastebin.com/32uuK33E
音频服务:https : //pastebin.com/ShiUfBMc
清单:https : //pastebin.com/kPp7RSYK
因为“到 pastebin 的链接必须附有代码”
这是意图(我已经尝试了相关标志的所有组合,所以我真的怀疑这就是问题所在)
// creates an intent which opens the application when the notification is pressed
private PendingIntent getPendingIntent(Context context) {
Intent intent = getIntent(this);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(intent);
return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
// returns an intent which resumes the Main Activity and passes various song information
private Intent getIntent(Context context) {
int duration = player != null ? player.getDuration() : 0;
boolean playing = player != null && player.isPlaying();
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra(MediaPlayerContract.INTENT_EXTRA_SONG_INFO, getSongInfo());
intent.putExtra(MediaPlayerContract.INTENT_EXTRA_POS, currentQueuePos);
intent.putExtra(MediaPlayerContract.INTENT_EXTRA_DURATION, duration);
intent.putExtra(MediaPlayerContract.INTENT_EXTRA_IS_PLAYING, playing);
return intent;
}
冉冉说
翻过高山走不出你
慕姐4208626
相关分类