2012-02-09 75 views
0

我有MyActivity和MyService(播放音乐)。我也有通知(在通知栏中),但是当我按下时,MyActivity在默认状态下打开(播放按钮没有按下,例如,虽然音乐仍在播放)。这在我开始使用绑定工作之前就行得通了 - 我担心它必须对它进行一些操作。Android:通知和绑定服务

什么可能是错的?


编辑:

这是我的我的服务里面Noification:

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

考虑增加此标志为Intent您正在使用您的通知:

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 

这样你的Activi的新实例如果它存在,ty不会被创建。

+0

其实我使用PendingIntent(在开发者指南教程中工作),它没有这种类型的标志。或者你的意思是我开始服务的意图?另外,请看第一篇文章更新。 – 2012-02-09 18:26:26

+0

不是'PendingIntent',你传递给'PendingIntent'的'Intent'。 – 2012-02-09 18:27:59

+0

谢谢,现在它按预期工作。 – 2012-02-09 18:52:08