2013-09-24 5 views
0

대상 활동에 ID를 보낸 Android 알림이 있습니다. 는이를 위해, 나는이 같은 putExtra와 의도를 사용여러 알림 인스턴스에서 설정/가져 오기

Intent resultIntent = new Intent(this.context, ConfirmationActivity.class); 

resultIntent.putExtra("Id", idToSent); 

resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

resultPendingIntent = PendingIntent.getActivity(this.context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

내가 알림 2, 3 또는 더 많은 시간을 호출 할 때 그것이 문제. Activity의 onCreate 메서드에서 "getExtras"를 사용할 때 항상 동일한 ID (마지막 알림 인스턴스에서 보낸 마지막 ID)가

의도의 플래그를 변경하려고했지만 찾을 수 없습니다. 올바른 조합

누군가가 도와 줄 수 있습니까?

내가 어떻게하면 알림의 3 가지 인스턴스를 가질 수 있으며 알림을 클릭하면 활동에 3 가지 ID가 전송됩니까?

// 알림 관리자 클래스

public void sendNearPromotionNotification(int idToSent){ 

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.context); 

    notificationBuilder.setContentTitle(context.getResources().getString(R.string.Title)); 
    notificationBuilder.setContentText(context.getResources().getString(R.string.Text)); 
    notificationBuilder.setTicker(context.getResources().getString(R.string.Ticket)); 
    notificationBuilder.setSmallIcon(R.drawable.icon); 

    int apiLevel = Integer.valueOf(android.os.Build.VERSION.SDK_INT); 

    PendingIntent resultPendingIntent = null; 

    if (apiLevel < Build.VERSION_CODES.JELLY_BEAN){  

     Intent resultIntent = new Intent(this.context, ConfirmationActivity.class); 

     resultIntent.putExtra("Id", idToSent); 

     resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

     resultPendingIntent = PendingIntent.getActivity(this.context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    }else{ 

     Intent addWishListIntent = new Intent(this.context, IntentServiceNotifications.class); 

     addWishListIntent.putExtra("Id", idToSent); 

     PendingIntent pendingIntent = PendingIntent.getService(this.context, 0, addWishListIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

     notificationBuilder.addAction(R.drawable.icon2, "Add a WishList", pendingIntent); 
    } 

    notificationBuilder.setAutoCancel(true); 

    notificationBuilder.setContentIntent(resultPendingIntent); 

    NotificationManager notificationManager = (NotificationManager)this.context.getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.notify(idToSent, notificationBuilder.build()); 
} 

// ConfirmationActivity 클래스

public class PromotionConfirmationActivity extends FragmentActivity { 

    private int id = 0; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     setTheme(android.R.style.Theme_Translucent_NoTitleBar); 

     super.onCreate(savedInstanceState); 

     setContentView(R.layout.layout_transparent); 

     Bundle extras = getIntent().getExtras(); 

     if(extras != null) 
      id = extras.getInt("Id"); 
    } 
} 

답변

0

이 같은 것을보십시오 :

이 내 전체 코드입니다

private static class IDGenerator { 

     private static final AtomicInteger counter = new AtomicInteger(); 

     public static int nextValue() { 
      return counter.getAndIncrement(); 
     } 
    } 


    ... 

    resultPendingIntent = PendingIntent.getActivity(this.context, IDGenerator.nextValue(), resultIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

문서 두 번째 매개 변수로 보낸 ID는 사용되지 않지만 실제로 이러한 용도로 필요하다고 주장합니다.

관련 문제