'Why AlertDetails.class is showing error in Android Notification's Pending Intent?
I am little bit new in Android and I am learning about Android Notifications, Actually I want to set the notification tap action and open my app when notification get clicked, I am referring it from Android Documentation,
So I am referring this code :
// Create an explicit intent for an Activity in your app
Intent intent = new Intent(this, AlertDetails.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
And I am getting error in Second Parameter of Intent Constructor i.e. AlertDetails.class.
So how should I fix it ?
Solution 1:[1]
Ahh, I got my answer... I just have to pass the ActivityName.class in second parameter of Intent Constructor same as a normal intent.
So corrected code for intent to open MainActivity after clicking on notification is :
// Create an explicit intent for an Activity in your app
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pranav Sangave |
