API 27中的startActivityForResult后崩溃 [英] Crashes after startActivityForResult in API 27

查看:207
本文介绍了API 27中的startActivityForResult后崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在突然更新到API 27和支持库27.0.2之后,我在Crashlytics中获得了很多这些堆栈跟踪信息:

After updating to API 27 and Support library 27.0.2 suddenly I get a lot of these stack traces in Crashlytics:

Fatal Exception: java.lang.IllegalArgumentException
    at android.os.Parcel.readException(Parcel.java:1544)
    at android.os.Parcel.readException(Parcel.java:1493)
    at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:5108)
    at android.app.Activity.isTopOfTask(Activity.java:5688)
    at android.app.Activity.startActivityForResult(Activity.java:3973)
    at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(Source:54)
    at android.support.v4.app.FragmentActivity.startActivityForResult(Source:67)

我这样称呼:

ActivityOptions options = ActivityOptions.makeCustomAnimation(activity, R.anim.slide_in_from_right, R.anim.fade_out);
startActivityForResult( intent, REQ_ACTION, options.toBundle());

我无法读取源代码,因为它尚未发布.我什至尝试替换并使用android-26代码,但这是不同的.

I cannot read the source code as it is not released yet. I even tried to replace and use android-26 code, but it's different.

上面的调用有一个警告,说只能从同一库组调用BaseFragmentActivityApi16.startActivityForResult,因此我使用ActivityCompat对其进行了修复,但我认为它不能解决崩溃问题.

There is a warning for the above call saying that BaseFragmentActivityApi16.startActivityForResult can only called from the same library group, so I fixed it by using ActivityCompat, but I don't think it will solve the crash problem.

这是平台问题还是可以解决?

Is this a platform issue or can I fix this?

修改

if (Build.VERSION.SDK_INT >= 21) {
    ActivityOptions options = ActivityOptions.makeCustomAnimation(activity, R.anim.slide_in_from_right, R.anim.fade_out);
    startActivityForResult(intent, REQ_ACTION, options.toBundle());
} else {
    ActivityOptions options = ActivityOptions.makeCustomAnimation(activity, R.anim.slide_in_from_right, R.anim.fade_out);
    ActivityCompat.startActivityForResult(this, intent, REQ_ACTION, options.toBundle());
}

如果我根据评论中的链接将其更改为以上内容,则Android Studio会像上面那样抱怨.这可能与问题有关.

If I change it to the above according to the link in my comment, Android Studio complaining like above. This might be related to the problem.

推荐答案

您可以尝试以下代码.

You can try this code.

startActivityForResult( intent, REQ_ACTION)
overridePendingTransition(R.anim.slide_in_from_right,  R.anim.fade_out);

这篇关于API 27中的startActivityForResult后崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆