[英]AndroidRuntimeException from Google Play Crash Report
I have an app on the Google play store and it works fine for most people. 我在Google Play商店中有一个应用,对大多数人来说都可以正常运行。 However there are 90 crashes reported, via Google crash report, with the following:
但是,通过Google故障报告报告了90起崩溃,其中包括:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:847)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:242)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:330)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4429)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:3151)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:2918)
at dalvik.system.NativeStart.main(Native Method)
I've had a look around on the web but all I can find is to add intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
我在网上浏览了一下,但是我所能找到的只是添加
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
. 。
But this doesn't work for me as I don't call startActivity()
in my code. 但这对我不起作用,因为我没有在代码中调用
startActivity()
。 I do call startActivityForResult()
but specifying the FLAG_ACTIVITY_NEW_TASK
flag stops the result being returned in onActivityResult()
. 我确实调用了
startActivityForResult()
但指定FLAG_ACTIVITY_NEW_TASK
标志将停止在onActivityResult()
返回结果。
Here is the only piece of code that has startActivityForResult()
called from onCreate()
in my Main Activity: 这是在我的主要活动中唯一具有从
onCreate()
调用startActivityForResult()
的代码:
private void load()
{
Intent loadBeats = new Intent(this, BeatListActivity.class);
startActivityForResult(loadBeats, SELECT_BEAT_ACTIVITY);
}
I've never actually had this error occur for me on any of my devices or in a Virtual Device! 在我的任何设备或虚拟设备上,我从未真正发生过此错误! This all makes it difficult to solve.
这一切都很难解决。
Any ideas? 有任何想法吗?
After the helpful comments, @ReubenScratton, following my question I think I've found the problem/solution! 在提出有用的评论之后,@ ReubenScratton,在我提出问题之后,我想我已经找到了问题/解决方案!
In my code I do not use startActivity()
so this confused me. 在我的代码中,我不使用
startActivity()
,这使我感到困惑。 However I do use AdView (admob adverts) version 4.1.1, which does seem to call startActivity()
. 但是我确实使用了AdView(admob广告)4.1.1版,它似乎确实调用了
startActivity()
。 I found this out after searching Google. 我在搜索Google后发现了这一点。 Other people had reported the same errors, as per my question, using that version of AdView (GoogleAdMobAdsSdk-4-1-1.jar).
根据我的问题,其他人使用该版本的AdView(GoogleAdMobAdsSdk-4-1-1.jar)报告了相同的错误。
I've updated my app with a newer version and, so far, there have been no more errors! 我已经用较新的版本更新了我的应用程序,到目前为止,没有更多错误了!
I will report back if this is not the case thought. 如果不是这种情况,我将报告。
Just Adding up 只是加起来
This exception also happens with interstitial ads 插页式广告也会发生这种情况
You have to pass the activity context not application context 您必须传递活动上下文而不是应用程序上下文
InterstitialAd interstitial = new InterstitialAd(this);
Incase of fragments 如果有碎片
InterstitialAd interstitial = new InterstitialAd(getActivity());
and not 并不是
InterstitialAd interstitial = new InterstitialAd(getActivity().getApplicationContext());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.