Friday, June 7, 2013

[android help] android notification shows just the last notificatoin


android notification shows just the last notificatoin



I have application android which gives data from server, i want to make notifications, one notification for each row of data, I want when the user press on the notification, an activity is triggered, i want to do all that using android service, i could do all of that.


my problem is that whatever the notification the user press, it just shows the last row of data.


code:



lient client = new Client(Configuration.getServer());
String str = client.getBaseURI("offers");
try {
JSONArray json = new JSONArray(str);
for (int i = 0; i < json.length(); i++) {
JSONObject oneOffer = json.getJSONObject(i);
int offerID = oneOffer.getInt("ID");
String offerDescriptoin = oneOffer.getString("Description");
String endDate = oneOffer.getString("EndDate");
String startDate = oneOffer.getString("StartDate");
JSONObject restaurant = oneOffer.getJSONObject("Restaurant");
int restaruantID = restaurant.getInt("ID");
String restaurantName = restaurant.getString("Name");
Offer offer = new Offer(offerID, startDate, endDate,
offerDescriptoin, new Restaurant(restaruantID,
restaurantName));
Log.d("DES", offerDescriptoin);
Offer.getAllOffers().put(offer.getID(), offer);
Intent intent = new Intent(this, OfferNotification.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0,
intent, 0);
Uri soundUri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_launcher)
.addAction(R.drawable.ic_launcher, "call", pIntent)
.addAction(R.drawable.ic_launcher, "more", pIntent)
.addAction(R.drawable.ic_launcher, "add more", pIntent)
.setContentTitle("Offer from " + restaurantName)
.setContentText(offerDescriptoin).setSound(soundUri);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, OfferNotification.class);
resultIntent.putExtra("offerID", offer.getID());
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

stackBuilder.addParentStack(OfferNotification.class);

stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

mNotificationManager.notify(offer.getID(), mBuilder.build());
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...