2012-12-12 3 views
1

나는 2 개의 Notifications을 가지고 있습니다. 하나는 수신 메시지 용이고 다른 하나는 발신 메시지 용입니다. Notification 클릭하면 PendingIntent이 자기에게 보냅니다.Android onNewIntent는 항상 동일한 의도를받습니다.

private static final int INID = 2; 
private static final int OUTID = 1; 

private void update(boolean incoming, String title, String message, int number) { 
    notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
    Intent intent = new Intent(this, Entry.class); 
    intent.putExtra((incoming ? "IN" : "OUT"), incoming); 
    PendingIntent pi = PendingIntent.getActivity(Entry.this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); 
    Notification noti = new Notification(incoming ? R.drawable.next : R.drawable.prev, incoming ? "Incoming message" : "Outgoing message", System.currentTimeMillis()); 
    noti.flags |= Notification.FLAG_NO_CLEAR; 
    noti.setLatestEventInfo(this, title, message, pi); 
    noti.number = number; 
    notificationManager.notify(incoming ? INID : OUTID, noti); 
} 

을 그리고 onNewIntent 방법에 Intent을 캡처 : 하나 개의 작업 만이 있다는

@Override 
protected void onNewIntent(Intent intent) { 
    setIntent(intent); 
    if (intent.getExtras() != null) 
     for (String id : new ArrayList<String>(intent.getExtras().keySet())) { 
      Object v = intent.getExtras().get(id); 
      System.out.println(id + ": " + v); 
     } 
    else 
     log("onNewIntent has no EXTRAS"); 
} 

플러스 확실하게 manifest 라인 나는 클릭 된 Notifications 하는지를 판단하기 위해 추가 가치에 넣어 (activity 태그) :

android:launchMode="singleTop" 

나는 그것이을 통해 실행되는 기록메서드를 사용하지만 항상 같은 intent (IE를 클릭하거나 입력 할 경우 , 추가 인 텐트에는 항상 bundle (로그 : OUT: false)이 포함됩니다.

private void buttonClick(View v) {  
    update(true, "IN", "in", 1); 
    update(false, "OUT", "out", 3); 
} 

private void setNotificationSettings() { 
    update(false, "IN", "===out message===", 0); 
    update(true, "OUT", "===in message===", 0); 
} 

는 왜 항상 같은 (마지막 생성) Intent을 받는가 : 모두 의도의 초기화들이이 변경 될 때보다 다른 순서로 발생하기 때문에 항상 내가 발견 마지막으로 생성 된 의도인가? 당신은 모든 목적을 위해 같은 requestcode을 전달하는

답변

6

당신은 마지막으로 의도 매번 reciev, 그래서 당신은 같은 코드 아래로 ..중인 의도에서 다른 requestcode을 통과

을 왜

귀하의 코드 :

PendingIntent pi = PendingIntent.getActivity(Entry.this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); 

필요가 변경 :

PendingIntent pi = PendingIntent.getActivity(Entry.this, your_request_code, intent, Intent.FLAG_ACTIVITY_NEW_TASK); 
+0

요청 코드는 어떻게 정의합니까? 또는 각 통지마다 하나씩 두 개의 요청 코드를 만들어야합니까? 아니면 그냥 '알림 id'와 동등해야합니까? 나는 지금 당신이 말한 라인에이 코드를 가지고있다. 678452056 : 678452099' 그리고 그 방법으로 고마워요. – stealthjong

+0

위대한 .. 당신을 환영합니다 .. 요청은 모든 의도에 대해 유일해야합니다 .. –

+0

'Intent.FLAG_ACTIVITY_NEW_TASK'은 여기에 속하지 않습니다 – Richard

관련 문제