2 уведомления, только одно я могу открыть, другое не запустило мою деятельность - PullRequest
0 голосов
/ 27 октября 2011

Моя проблема заключается в том, что когда я отправляю более одного уведомления (с сервера на телефон через c2dm), я получаю их все со всей их информацией.

Я вижу, что у меня есть две иконки с уведомлениями. Когда я нажимаю один из них с моей информацией (я нажал на нее, я получаю активность), другой, как не соответствует действительности ... не начал деятельность.

Я прочитал кое-что о PendingIntent, которое однажды начало активности, но я не знаю, что делать.

Мне нужно получать каждое уведомление, а не только последнее (это не похоже на обновление).

private void incomingTestp(JSONObject json, Context context) throws JSONException {
    Intent intent = new Intent(context, TestpViewActivity.class);
    Testp testp = Testp.fromJSON(json);

    TestpServiceUtil.save(testp);
    intent.putExtra("testpId", testp.getTestpId());

    sendNotification("New Testp", "update", intent, testp.getTestpId(), context);
}

private void incomingTestr(JSONObject json, Context context) throws JSONException {
    Intent intent = new Intent(context, TestrViewActivity.class);
    Testr Testr = Testr.fromJSON(json);

    TestrServiceUtil.save(testr);
    intent.putExtra("testrId", testr.getTestrId());

    sendNotification("New Testr", "update", intent, report.getTestrId(), context);

}   

private void sendNotification(String title, String description, Intent intent, long id, Context context) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.icon, title, System.currentTimeMillis());
    intent.putExtra("force", true);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.setLatestEventInfo(context.getApplicationContext(), title, description, PendingIntent.getActivity(context, requestCode++, intent, Intent.FLAG_ACTIVITY_NEW_TASK));
    notification.vibrate = new long[] { 0, 200, 100 };
    //notification.defaults |= Notification.DEFAULT_SOUND;
    notificationManager.notify("Test", (int) id, notification);

}

Я дам вам немного больше информации, чтобы узнать, как я называю этот метод.

1 Ответ

1 голос
/ 27 октября 2011

try: PendingIntent.getActivity (context, requestCode ++, intent, 0);

...