Android 处理多个通知的点击事件

Android 处理多个通知的点击事件,android,android-activity,notifications,android-pendingintent,Android,Android Activity,Notifications,Android Pendingintent,在我的应用程序中,我已经为朋友的生日创建了通知。如果有多个朋友的生日,它将打开多个通知。 我的问题:-如果我单击第一个通知,它必须触发一个活动。假设Activity1 如果我单击另一个通知,它必须触发另一个活动,比如Activity2 NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE);

在我的应用程序中,我已经为朋友的生日创建了通知。如果有多个朋友的生日,它将打开多个通知。 我的问题:-如果我单击第一个通知,它必须触发一个活动。假设Activity1 如果我单击另一个通知,它必须触发另一个活动,比如Activity2

        NotificationManager nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Resources res = context.getResources();

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent1 = new Intent(context, FragmentActivity1.class);
        String pass = name;
        resultIntent1.setData(new Uri.Builder().scheme("data")
                .appendQueryParameter("text", "my text").build());
        resultIntent1.putExtra("title", pass);
        resultIntent1.putExtra("uid", i);

        TaskStackBuilder stackBuilder1= TaskStackBuilder.create(context);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder1.addParentStack(FragmentActivity1.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder1.addNextIntent(resultIntent1);
        PendingIntent resultPendingIntent1 = stackBuilder1.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.cake)
                .setLargeIcon(
                        BitmapFactory.decodeResource(res,
                                R.drawable.cake))
                .setTicker("BirthDay " + name)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle(name)
                .setContentIntent(resultPendingIntent1);

        Notification n = builder.build();
        n.flags = Notification.FLAG_NO_CLEAR;
        nm.notify(i++, n);
有办法吗?请帮帮我。谢谢

        NotificationManager nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Resources res = context.getResources();

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent1 = new Intent(context, FragmentActivity1.class);
        String pass = name;
        resultIntent1.setData(new Uri.Builder().scheme("data")
                .appendQueryParameter("text", "my text").build());
        resultIntent1.putExtra("title", pass);
        resultIntent1.putExtra("uid", i);

        TaskStackBuilder stackBuilder1= TaskStackBuilder.create(context);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder1.addParentStack(FragmentActivity1.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder1.addNextIntent(resultIntent1);
        PendingIntent resultPendingIntent1 = stackBuilder1.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.cake)
                .setLargeIcon(
                        BitmapFactory.decodeResource(res,
                                R.drawable.cake))
                .setTicker("BirthDay " + name)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle(name)
                .setContentIntent(resultPendingIntent1);

        Notification n = builder.build();
        n.flags = Notification.FLAG_NO_CLEAR;
        nm.notify(i++, n);

`

您应该只使用一个活动。根据单击的通知,您可以使用内容填充活动。ohk..但我总是在结果活动中获得相同的内容。假设我单击第一个通知并在结果活动中获得额外值。然后,如果我单击第二个通知也在结果活动中获得相同的额外值..我将如何做帮助我。使用列表视图进行通知。注册listView.onItemClickListener(),以便可以获得单击的项目的位置。
        NotificationManager nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Resources res = context.getResources();

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent1 = new Intent(context, FragmentActivity1.class);
        String pass = name;
        resultIntent1.setData(new Uri.Builder().scheme("data")
                .appendQueryParameter("text", "my text").build());
        resultIntent1.putExtra("title", pass);
        resultIntent1.putExtra("uid", i);

        TaskStackBuilder stackBuilder1= TaskStackBuilder.create(context);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder1.addParentStack(FragmentActivity1.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder1.addNextIntent(resultIntent1);
        PendingIntent resultPendingIntent1 = stackBuilder1.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.cake)
                .setLargeIcon(
                        BitmapFactory.decodeResource(res,
                                R.drawable.cake))
                .setTicker("BirthDay " + name)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle(name)
                .setContentIntent(resultPendingIntent1);

        Notification n = builder.build();
        n.flags = Notification.FLAG_NO_CLEAR;
        nm.notify(i++, n);