How to set click listener for notification?

As for yoshi24’s comment, you may be able to set extras like this.

final Intent intent = new Intent(this, MyActivity.class);
intent.setData(data);
intent.putExtra("key", "value");
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

You need to be aware of this as well before going for pending intents

https://stackoverflow.com/questions/1198558/how-to-send-parameters-from-a-notification-click-to-an-activity

UPDATE
some thing like this will work for you

int your mainfest

<activity android:name=".MyActivity" android:launchMode="singleTop" ... />

in your activity

@Override
protected void onCreate(Bundle savedInstanceState) {
    processIntent(getIntent());
}

@Override
protected void onNewIntent(Intent intent) {     
    processIntent(intent);
};

private void processIntent(Intent intent){
    //get your extras
}

Leave a Comment