how to change notification to another when clicked- android

199 views Asked by At

My app is for display a notification which is much like a reminder. So far, I can display my text on the notification box. But I want it to switch to another notification when user clicks on it.

here is my code: `else{

  Text = "go to shopping mall";
  Text2 = "meet emma";
 final PendingIntent pending = PendingIntent.getActivity(arg0.getContext(), 0, new         Intent(arg0.getContext(),MainActivity.class), 0);
new AsyncTask<Void, Void, Void>(){

    public Void doInBackground(Void... args){


        Bitmap bmp = BimapFactory.decodeResource(arg0.getContext().getResources(), R.drawable.image);

        notification = new NotificationCompat.Builder(arg0.getContext())
         .setContentTitle("I want to...")
         .setContentText(Text)
         .setContentIntent(pending)
         .setSmallIcon(R.drawable.ic_launcher)
         .setStyle(new NotificationCompat.BigPictureStyle()
             .bigPicture(bmp))
         .build();
        notificationmanager = (NotificationManager)arg0.getContext().getSystemService(Context.NOTIFICATION_SERVICE);

        notificationmanager.notify(notificationId, notification);
        notificationId++;
        return null;
    }
}.execute();

`

This works exactly how I wanted. But I want to display *Text2 when user clicks on the notification.*

*Note:*For now, when I click on this notification,it brings me to the application itself, which is intended. But this should now only change the text, without taking me somewhere else.

Please, consider re-edit my code to explain,if possible.

1

There are 1 answers

2
corsair992 On

You should be able to achieve this by implementing a BroadcastReceiver as a click listener, changing your action PendingIntent to point to it, and updating your Notification with the new text from the BroadcastReceiver callback.