How to display multiple notifications in android

前端 未结 18 1397
既然无缘
既然无缘 2020-11-29 19:39

I am receiving only one notification and if there comes another notification, it replaces the previous one and here is my code

private static void generateNo         


        
18条回答
  •  猫巷女王i
    2020-11-29 20:12

    Use the following method in your code.

    Method call :-

    notificationManager.notify(getCurrentNotificationId(getApplicationContext()), notification);
    

    Method:-

      *Returns a unique notification id.
             */
    
            public static int getCurrentNotificationId(Context iContext){
    
                NOTIFICATION_ID_UPPER_LIMIT = 30000; // Arbitrary number.
    
                NOTIFICATION_ID_LOWER_LIMIT = 0;
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(iContext);
            int previousTokenId= sharedPreferences.getInt("currentNotificationTokenId", 0);
    
            int currentTokenId= previousTokenId+1;
    
            SharedPreferences.Editor editor= sharedPreferences.edit();
    
            if(currentTokenId

提交回复
热议问题