Android 不是从通知开始的活动

Android 不是从通知开始的活动,android,firebase,google-cloud-firestore,android-notifications,Android,Firebase,Google Cloud Firestore,Android Notifications,我正在尝试设置我的通知以直接导致特定活动。我遵循报告中概述的步骤。但是单击通知只会打开应用程序的主启动器 我试图通过通知启动的活动是DetailActivity 这就是我在manifest.xml中设置活动层次结构的方式 <activity android:name=".SplashscreenActivity"> <intent-filter> <action android:name="androi

我正在尝试设置我的通知以直接导致特定活动。我遵循报告中概述的步骤。但是单击通知只会打开应用程序的主启动器

我试图通过通知启动的活动是DetailActivity

这就是我在manifest.xml中设置活动层次结构的方式

    <activity
        android:name=".SplashscreenActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".HomeActivity"
        android:parentActivityName=".SplashscreenActivity"/>
    <activity
        android:name=".DetailActivity"
        android:parentActivityName=".HomeActivity"/>
getNotification
方法:

private Notification getNotification(String title, String text, PendingIntent intent) {

    return new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(text)
            .setContentIntent(intent)
            .setOngoing(true)
            .build();
}
我不知道这个问题是否是因为我试图启动的活动不是启动器活动的直接子项。我也不知道如何调试它。希望以前有人遇到过这个奇怪的问题

使用以下命令:

Intent notificationIntent = new Intent(this, DetailActivity.class);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent. FLAG_ONE_SHOT);
并在通知中使用此挂起内容

 Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"x")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("your title")
                .setAutoCancel(true)
                .setSound(soundUri)
                .setContentIntent(pendingIntent)
                .setPriority(Notification.PRIORITY_HIGH);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notificationBuilder.build());

通知代码

一个快速修复方法是从您的启动器活动重定向到详细的活动。@AbdulRehman是否有办法通过通知单击来检测启动器何时启动?我想这会有帮助@AbdulRehman我在我的帖子中已经提到了相同的链接。我已经按照谷歌漫游的步骤进行了。尝试一些非零请求代码,用于
getpendingent
FLAG\u ACTIVITY\u CLEAR\u TOP不是pendingent类的一部分。虽然这可能会回答这个问题,但代码块本身通常不是有用的答案,更可能吸引反对票。建议您解释您正在展示的解决方案的作用,以及该代码为什么/如何回答问题。无需告诉开发人员该代码是如何工作的,他是开发人员和任何类型的孩子:P@MuhammadWaqas你的答案不仅会被提问者阅读(和投票),也会被其他用户阅读(和投票)。如果没有解释,他们可能无法理解代码块。这就是为什么没有解释的代码块答案不被认为是好答案,可能会被否决。您可以编辑您的答案以使其更好。
 Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"x")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("your title")
                .setAutoCancel(true)
                .setSound(soundUri)
                .setContentIntent(pendingIntent)
                .setPriority(Notification.PRIORITY_HIGH);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notificationBuilder.build());