1

I have a weird problem with my notification click. Here's how i create the notification:

Intent contentIntent;
            if (appointmentId == null) {
                // not an appointment message
                contentIntent = ConversationDetailsActivity.getLaunchIntent(this, conversationId);
            } else {
                // appointment message
                contentIntent = AppointmentDetailsActivity.getLaunchIntent(this, appointmentId);
            }
            PendingIntent contentPendingIntent = PendingIntent.getActivity(this, conversationId.hashCode(), contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder =
                    new NotificationCompat.Builder(this)
                            .setSmallIcon(R.drawable.ic_bubble_24dp)
                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                            .setContentTitle(getString(R.string.notification_title))
                            .setContentText(message)
                            .setContentIntent(contentPendingIntent)
                            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                            .setVibrate(new long[]{0, 1000, 1000, 1000, 1000})
                            .setLights(Color.WHITE, 3000, 3000);

            manager.notify(conversationId.hashCode(), builder.build());

When i get the 'appointmentId', notification click actually launches AppointmentDetailsActivity. When appointmentId is null, it should launch ConversationDetailsActivity, but it launches MainActivity instead. I have tried the android:exported="true" solution, but it didn't work. The 'getLaunchIntent' methods of both activities are identical, manifest declarations are the same too. Notification is created from a Service. I am puzzled. Please help me launch the right activity. Thank you.

The getLaunchIntent for AppointmentDetailsActivity (the one that works):

public static Intent getLaunchIntent(final Context context, final String appointmentId) {
    Intent intent = new Intent(context, AppointmentDetailsActivity.class);
    intent.putExtra("appointmentId", appointmentId);
    return intent;
}

getLaunchIntent method for ConversationDetailsActivity (the one that doesnt' work):

public static Intent getLaunchIntent(final Context context, final String conversationId) {
    Intent intent = new Intent(context, ConversationDetailsActivity.class);
    intent.putExtra("conversationId", conversationId);
    return intent;
}

And manifest declarations:

<activity
    android:name=".ui.conversations.ConversationDetailsActivity"
    android:windowSoftInputMode="stateHidden"
    />
<activity android:name=".ui.appointments.AppointmentDetailsActivity"/>

This answer here solved the issue.

Community
  • 1
  • 1

0 Answers0