gpt4 book ai didi

android - TaskStackBuilder#startActivities() NullPointerException

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:23 26 4
gpt4 key购买 nike

我在 4.4.2 和 4.4.3 设备上不断发生崩溃(尽管我不确定这是 API 问题),在某些 ParsePushBroadcastReceiver 中,以下代码导致 NullPointerException 位于 startActivities 调用的深处。

Intent intent = new Intent(context, SomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
TaskStackBuilder.create(context)
.addParentStack(SomeActivity.class)
.addNextIntent(intent)
.startActivities();

我已经尝试测试上下文是否为空,但是,Intent 实例化会捕捉到这一点。可能还值得注意的是,此应用程序正在使用 Parse Push。这次崩溃的崩溃日志:

java.lang.RuntimeException: Unable to start receiver com.example.app.android.receiver.PushReceiver: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2567)
at android.app.ActivityThread.access$1800(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1471)
at android.os.Parcel.readException(Parcel.java:1419)
at android.app.ActivityManagerProxy.startActivities(ActivityManagerNative.java:4494)
at android.app.Instrumentation.execStartActivitiesAsUser(Instrumentation.java:1496)
at android.app.Instrumentation.execStartActivities(Instrumentation.java:1458)
at android.app.ContextImpl.startActivities(ContextImpl.java:1465)
at android.content.ContextWrapper.startActivities(ContextWrapper.java:350)
at android.content.ContextWrapper.startActivities(ContextWrapper.java:350)
at android.support.v4.content.ContextCompatJellybean.startActivities(ContextCompatJellybean.java:26)
at android.support.v4.content.ContextCompat.startActivities(ContextCompat.java:105)
at android.support.v4.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:325)
at android.support.v4.app.TaskStackBuilder.startActivities(TaskStackBuilder.java:301)
at com.example.app.android.receiver.PushReceiver.routePush(PushReceiver.java:59)
at com.example.app.android.receiver.PushReceiver.onPushOpen(PushReceiver.java:35)
at com.parse.ParsePushBroadcastReceiver.onReceive(ParsePushBroadcastReceiver.java:108)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2552)
at android.app.ActivityThread.access$1800(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)

最佳答案

我无法解决这个问题,因为我怀疑这可能是 4.4.* 设备特有的错误。作为替代方案,我将使用 TaskStackBuilder 替换为通过 PendingIntent.getActivities 创建我的 Activity 。就我而言,这提供了等效的功能,并且是一个直接的替代品。也许您也会发现它很有用。

final Intent parentIntent = new Intent(context, ParentActivity.class);
parentIntent.putExtra(ParentActivity.EXTRA, extraValue);

final Intent childIntent = new Intent(context, ChildActivity.class);
childIntent.putExtra(ChildActivity.EXTRA, extraChildValue);
childIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

final Intent[] intents = new Intent [] {parentIntent, childIntent};
PendingIntent pendingIntent = PendingIntent.getActivities(context, INTENT_REQUEST_CODE, intents, PendingIntent.FLAG_ONE_SHOT);

pendingIntent.send();

关于android - TaskStackBuilder#startActivities() NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28754754/

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