How to implement grouped notifications similar to email apps on Android

I want to build grouped notifications on Android that work like popular email clients where multiple messages appear stacked under a single notification header.

Currently I can only make individual notifications using this approach:

public void buildSimpleNotification(String headerText, String bodyContent, String displayText) {
    int iconResource = R.drawable.app_notification_icon;
    CharSequence tickerDisplay = displayText;
    long timestamp = System.currentTimeMillis();
    Context appContext = getApplicationContext();
    CharSequence notificationHeader = headerText;
    CharSequence notificationBody = bodyContent;
    Intent launchIntent = new Intent(this, HomeActivity.class);
    
    Bundle extras = new Bundle();
    extras.putString("header", headerText);
    extras.putString("content", bodyContent);
    
    launchIntent.putExtras(extras);
    PendingIntent actionIntent = PendingIntent.getActivity(this, 0,
        launchIntent, PendingIntent.FLAG_ONE_SHOT
        + PendingIntent.FLAG_UPDATE_CURRENT);
    String serviceType = Context.NOTIFICATION_SERVICE;
    
    NotificationManager notificationService = (NotificationManager) getSystemService(serviceType);
    Notification singleNotification = new Notification(iconResource, tickerDisplay, timestamp);
    singleNotification.setLatestEventInfo(appContext, notificationHeader, notificationBody, actionIntent);
    singleNotification.defaults |= Notification.DEFAULT_LIGHTS;
    singleNotification.defaults |= Notification.DEFAULT_SOUND;
    singleNotification.defaults |= Notification.FLAG_AUTO_CANCEL;
    singleNotification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    final int NOTIFICATION_ID = 0;
    notificationService.notify(NOTIFICATION_ID, singleNotification);
}

How can I create a notification group where I can stack multiple notification items together instead of showing them separately?

your code’s pretty outdated. for grouped notifications, just assign a group string to each one with setGroup(), then make a summary notification using setGroupSummary(true). you’ll need notification channels for api 26+. try setGroup(“email_group”) on each notification - that should work.

You’ll need to ditch that old Notification constructor and switch to NotificationCompat.Builder with proper grouping. I ran into this same issue updating old notification code last year. Set up notification channels for Android O+ and make sure your group keys are right. For each notification, use setGroup(“your_group_key”) and create one summary notification with setGroupSummary(true). The summary becomes the collapsed header users see first. When they tap to expand, the individual notifications show up below. Keep your group key the same across related notifications - if it’s inconsistent, Android won’t stack them. Don’t forget to handle single notifications - Android shows them ungrouped automatically, which is normal.

That Notification constructor’s been deprecated for years - you’re using really old code. For grouped notifications, switch to NotificationCompat.Builder with channels and group keys. Create a notification channel first (Android 8.0+), then build your individual notifications with the same group key using setGroup(). You’ll need a summary notification as the parent too. The trick is making sure all related notifications share the same group identifier, plus one summary notification with setGroupSummary(true). I ran into the same thing migrating from the old API - grouped notifications are way cleaner once you nail the channel setup. Just remember to handle different Android versions since channels are required on newer ones.