从小部件打开应用程序时返回堆栈导航不起作用

back stack navigation when opening the app from a widget is not working

我想在用户单击小部件中的产品时启动 DetailActivty

我使用的代码是这样的。设置 PendingIntentTemplete

ProductWigetProvider.class

Intent detailActivityIntent = new Intent(context, ProductDetailActivity.class);
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ProductDetailActivity.class);
    taskStackBuilder.addNextIntent(detailActivityIntent);

    PendingIntent pendingIntent = taskStackBuilder.getPendingIntent( 1,PendingIntent.FLAG_UPDATE_CURRENT);

    views.setPendingIntentTemplate(R.id.widget_list_view,pendingIntent);

和这段代码来设置 fillInIntent ProductRemoteViewFactory.class

Intent fillInIntent = new Intent();
    fillInIntent.setData(uri);
    views.setOnClickFillInIntent(R.id.widget_list_item_container,fillInIntent);

我的清单是

<activity
        android:name=".ui.EditProductActivity"
        android:label="@string/title_activity_add_new_item"
        android:parentActivityName=".ui.ProductDetailActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.dharmaraj.inventorymanager.ui.ProductDetailActivity" />
    </activity>

当我从窗口小部件打开 DetailActivty,然后按返回键时,应用程序关闭而没有打开主 CatalogActivty。

尝试类似于以下代码的操作(旨在从通知中启动详细信息 activity):

Intent backIntent = new Intent(context, MainActivity.class);
        backIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Intent action = new Intent(context, DetailActivity.class);

PendingIntent operation =
                PendingIntent.getActivities(this, 0, new Intent[] {backIntent, action}, PendingIntent.FLAG_CANCEL_CURRENT);

希望对您有所帮助!