gpt4 book ai didi

带有 TaskStackBuilder.addParentStack 的 Android parentActivityName 停止在 API 21 (Lollipop) 上工作

转载 作者:行者123 更新时间:2023-11-29 14:37:34 25 4
gpt4 key购买 nike

当从小部件打开应用程序时,我正在使用此代码设置返回堆栈导航。

Intent intent = new Intent(context, ComposeActivity.class);

// Create an Intent to launch ComposeActivity

intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

// Adds the back stack
stackBuilder.addParentStack(ComposeActivity.class);

// Adds the Intent to the top of the stack
stackBuilder.addNextIntent(intent);

// Gets a PendingIntent containing the entire back stack
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

// Get the layout for the App Widget and attach an on-click listener to the button

RemoteViews recordButtonImageView = new RemoteViews(
context.getPackageName(), R.layout.record_widget
);

recordButtonImageView.setOnClickPendingIntent(
R.id.record_button, pendingIntent
);

这是我的 AndroidManifest.xml 定义

<activity
android:name=".activities.ComposeActivity"
android:label="@string/compose_activity"
android:parentActivityName=".activities.MyFeedActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.NoActionBar">

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MyFeedActivity"/>

</activity>

它适用于 API 14 - 20 但不适用于 API 21。

我做错了什么?

最佳答案

我遇到了同样的问题。当我更改 getPendingIntent 方法中的 requestCode 参数时,问题就解决了。看来 requestCode 必须大于 0。所以你可以改变


PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);


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

关于带有 TaskStackBuilder.addParentStack 的 Android parentActivityName 停止在 API 21 (Lollipop) 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27421347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com