Android:通知和绑定服务

时间:2012-02-09 18:04:38

标签: android binding notifications

我有MyActivity和MyService(播放音乐)。我也有通知(在通知栏中)但是当我按下它时,MyActivity在默认状态下打开(例如,虽然音乐仍在播放,但没有按下播放按钮)。在我开始使用绑定之前,这工作正常 - 我担心它必须对它做一些事情。

可能出现什么问题?


修改

这是我服务中的通知:

PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), SoundRelaxerActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification();
notification.tickerText = "Soundrelaxer: "+trackTitle;
notification.icon = R.drawable.play;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.setLatestEventInfo(getApplicationContext(), "SoundRelaxer","Playing: " + trackTitle, pi);
startForeground(1, notification);

1 个答案:

答案 0 :(得分:1)

尝试将此标记添加到您在通知中使用的Intent

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

这样,如果存在活动的新实例,则不会创建该实例。