2013-12-10 3 views
-1

내 앱에서 활동이 있습니다. 내가 하나의 옵션을 클릭하면,이 같은 통지 내 서비스의 전경을 실행 시작 :알림 대기 중 알림 전경 서비스 android

PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, 
      new Intent(getApplicationContext(), Radio.class), 
      PendingIntent.FLAG_UPDATE_CURRENT); 

    Notification notification = new Notification(); 
    notification.tickerText = "Connecting RadiO!.. Wait.."; 
    notification.icon = R.drawable.ic_launcher; 
    notification.flags |= Notification.FLAG_ONGOING_EVENT; 
    notification.setLatestEventInfo(getApplicationContext(), "radiO!", 
      "Playing: " + songName, pi); 
    startForeground(1, notification); 

을 그리고, 여전히 내 활동을 실행, 내 알림을 클릭하고 나는 이전의 활동을 닫지 않고 그것을 열었다. 나는 같은 활동을 두 번해서는 안된다.

+1

http://developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse – CommonsWare

답변

0

당신이하고있는 일은 알림을 클릭 할 때마다 실행하려고하는 새로운 활동 인스턴스를 생성하고, 기존 활동 (있는 경우)을 재사용하기 위해 활동을 다음과 같이 설정합니다. 아래 그림과 같이 AndroidManifest.xml의 singleTask :

<activity 
     android:name=".YourActivity" 
     android:launchMode="singleTask"/> 

희망이 있습니다.

감사합니다.

+0

알림을 클릭하면 새로운 활동을 시작하고 알림을 닫습니다. – user3088957

+0

singleTask 속성을 사용하면 동일한 활동 두 번 ... –

+0

그것을 일하십시오! 고마워, 내 애플 리케이션이 필요합니다 : android : alwaysRetainTaskState = "true" – user3088957