Clicking on Notification is not starting intended activity?

后端 未结 7 1729
野性不改
野性不改 2020-11-30 09:32

I am using GCM in my application and also using NotificationManager to Create a Notification whenever GCM message is received.Till now everything is working perfectly and GC

7条回答
  •  死守一世寂寞
    2020-11-30 10:14

    Do some thing like this on generateNotification() method ..

    Replace your activity with Splash.Java class in it.

    /**
         * Issues a notification to inform the user that server has sent a message.
         */
        @SuppressWarnings("deprecation")
        private static void generateNotification(Context context, String message) {
            int icon = R.drawable.ic_launcher;
            long when = System.currentTimeMillis();
            //message = "vivek";
           // Log.d("anjan", message.split("~")[0]);
            //Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    
            NotificationManager notificationManager = (NotificationManager)
                    context.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification(icon, message, when);
    
            String title = context.getString(R.string.app_name);
            Log.d("anjan1", title);
            String text_message = context.getString(R.string.title_activity_main);
            Log.d("anjan1", text_message);
    
            Intent notificationIntent = new Intent(context, Splash.class);
            // set intent so it does not start a new activity
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                    Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
            notification.setLatestEventInfo(context, title, message, intent);
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
    
            // Play default notification sound
            notification.defaults |= Notification.DEFAULT_SOUND;
    
            // Vibrate if vibrate is enabled
            notification.defaults |= Notification.DEFAULT_VIBRATE;
            notificationManager.notify(0, notification);      
    
        }
    

提交回复
热议问题