2010-08-12 11 views
9

मैं अपने आवेदन में कई अधिसूचनाएं बनाने की कोशिश कर रहा हूं। प्रत्येक अधिसूचना को विशिष्ट रूप से पहचानने के लिए, मैंने उन्हें एक अद्वितीय पहचान दी है। बाद मेरी कोड है:एंड्रॉइड: एकाधिक अधिसूचनाएं प्रबंधित करना

private void updateNotification(int notificationId, int clockStatusID, CharSequence text) { 
//notificationManager.cancel(notificationId); 
// throws up an ongoing notification that the timer is running 
Log.i("TIMERCOUNT", "Notification id: " + notificationId); 
Notification not = new Notification(clockStatusID, // the 
    // icon 
    // for 
    // the 
    // status 
    // bar 
    text, // the text to display in the ticker 
    System.currentTimeMillis() // the timestamp for the 
    // notification to appear 
); 
Intent intent = new Intent(); 
intent.putExtra("notificationID", notificationId); 
intent.setAction("actionstring" + System.currentTimeMillis()); 
intent.setClassName("com.chander.time.android.activities", 
"com.chander.time.android.activities.Tabs"); 


not.setLatestEventInfo(self, 
    getText(R.string.timer_notification_title), 
    getText(R.string.timer_on_notification_text), PendingIntent 
    .getActivity(this, 0, intent, 
     PendingIntent.FLAG_UPDATE_CURRENT)); 

not.flags += Notification.FLAG_ONGOING_EVENT; 
not.flags += Notification.FLAG_NO_CLEAR; 
notificationManager.notify(notificationId, not); 
} 

समस्या: जब कोई सूचना चुना जाता है, टैब्स गतिविधि आशय गुजर कहा जाता है। मैं टैब में चयनित अधिसूचना की अनन्य अधिसूचना आईडी का उपयोग करना चाहता हूं। इरादे में अधिसूचना आईडी को बचाने के लिए मैंने intent.putExtra() की कोशिश की। लेकिन, कई अधिसूचनाओं के लिए यह अधिसूचना आईडी को ओवरराइट कर रहा है और नवीनतम लौटाता है। मैं समझ नहीं पा रहा हूं कि यह क्यों हो रहा है और मैं अधिसूचना आईडी के इस ओवरराइटिंग से कैसे बच सकता हूं।

धन्यवाद, चंदर

उत्तर

15

मैं इस सवाल का जवाब मिल गया। उद्देश्य में कैश हो रहे थे करने के लिए, एक नया आशय बनाने के सिर्फ कोड का निम्न भाग जोड़ें:।

saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); 

इस आशय अनूठा बनाता है।

इसके अलावा, किसी ने मुझे कोड का निम्न भाग आशय अद्वितीय बनाने के लिए सुझाव:

saveCallIntent.setAction("actionstring" + System.currentTimeMillis()); 

यह मेरी मदद था, लेकिन किसी और को मदद की हो सकती है।

7

--Chander सिर्फ notificationId बजाय 0 pendingIntent में रखते हैं।

PendingIntent.getActivity(this, notificationId, intent,PendingIntent.FLAG_UPDATE_CURRENT)); 

उपयोगकर्ता को यह काम करने के लिए उपरोक्त के साथ निम्नलिखित कोड को एक साथ अपडेट करना होगा।

mNotificationManager.notify(notificationId, mBuilder.build()); 
संबंधित मुद्दे