Search code examples
androidservicenotifications

Android: what is the id of startForeground(id,notification) in Service Class


What is the id parameter in startForground method in Service class.I found that answer by googling for single Notification.How do the guy find the id ? any list or reference for this.What if i want to show multiple notification like facebook. How do i define the id then ?

notification.flags = Notification.FLAG_NO_CLEAR;
startForeground(1337, notification);

Solution

  • Simple notification_id needs to be changeable.

    Just create random number for notification_id.

        Random random = new Random();
        int m = random.nextInt(9999 - 1000) + 1000;
    or
            int m = System.currentTimeMillis()%10000;
    

    and replace this line to add parameter for notification id as to generate random number

        startForeground(m, notification);