开始活动时获取java.lang.RuntimeException [英] Getting java.lang.RuntimeException while starting an activity

查看:199
本文介绍了开始活动时获取java.lang.RuntimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动A,当我想在她的内部开始此活动时,它是SingleTop,并带有另一个意图数据,例如:

I have an activity, A, which is SingleTop when I want to start this activity inside her, with another intent data, like this:

Intent intent = new Intent();
intent.setData(Uri.parse("something://someone"));
startActivity(intent);

发生此异常:

startActivityUncheckedLocked: task left null
V/ActivityManager(  596): java.lang.RuntimeException: here
V/ActivityManager(  596):   at com.android.server.am.ActivityStackSupervisor.startActivityUncheckedLocked(ActivityStackSupervisor.java:1646)
V/ActivityManager(  596):   at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1249)
V/ActivityManager(  596):   at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:741)
V/ActivityManager(  596):   at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3118)
V/ActivityManager(  596):   at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3104)
V/ActivityManager(  596):   at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:135)
V/ActivityManager(  596):   at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2071)
V/ActivityManager(  596):   at android.os.Binder.execTransact(Binder.java:404)

我该怎么办?我做错什么了吗?

What should I do? Am I doing anything wrong?

谢谢

编辑1
在我的AndroidManifest.xml文件中,我定义了something://以活动A打开.

EDIT 1
in my AndroidManifest.xml file, I defined something:// to open with activity A.

编辑2
当活动A不是singleTop时,就没有问题.

EDIT 2
when the activity A is not singleTop, there's no problem.

编辑3
此错误不会导致我的应用程序被自己强制关闭,实际上,问题是有时在收到此错误后,有时会出现如下错误:

EDIT 3
This error doesn't cause my app force closed by herself, in fact the problem is that sometimes exactly after getting this error, I get errors like this:

F/libc    (24873): Fatal signal 11 (SIGSEGV) at 0x00007074 (code=1), thread 24939 (Thread-2287)
I/DEBUG   (  195): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (  195): Build fingerprint: 'google/occam/mako:4.4.2/KOT49H/937116:user/release-keys'
I/DEBUG   (  195): Revision: '11'
I/DEBUG   (  195): pid: 24873, tid: 24939, name: Thread-2287  >>> com.blah.blah <<<
I/DEBUG   (  195): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00007074
I/DEBUG   (  195):     r0 779b9828  r1 4199b380  r2 00000014  r3 00007075
I/DEBUG   (  195):     r4 76b24ac0  r5 00000014  r6 00000000  r7 779b9828
I/DEBUG   (  195):     r8 774c3afc  r9 76c84d90  sl 76da6250  fp 774c3b14
I/DEBUG   (  195):     ip 733e9cec  sp 774c3ac0  lr 40a49b9d  pc 00007074  cpsr 00070030
I/DEBUG   (  195):     d0  0000000000000000  d1  0000000000000000
I/DEBUG   (  195):     d2  0000000000000000  d3  0000000000000000
I/DEBUG   (  195):     d4  0000000000000000  d5  0000000000000000
I/DEBUG   (  195):     d6  0000000000000000  d7  0000000000000000
I/DEBUG   (  195):     d8  0000000000000000  d9  0000000000000000
I/DEBUG   (  195):     d10 0000000000000000  d11 0000000000000000
I/DEBUG   (  195):     d12 0000000000000000  d13 0000000000000000
I/DEBUG   (  195):     d14 0000000000000000  d15 0000000000000000
I/DEBUG   (  195):     d16 0000000000000000  d17 0000000000000000
I/DEBUG   (  195):     d18 4a9b4d1ae3550b44  d19 1619de72ef18c72c
I/DEBUG   (  195):     d20 a5598b5ef3ee9d2c  d21 ea73a9b3cbecc5ff
I/DEBUG   (  195):     d22 1f5becf8adc083d0  d23 3f09f8604410f094
I/DEBUG   (  195):     d24 4000000000000000  d25 547d42aea2879f2e
I/DEBUG   (  195):     d26 40f86a0000000000  d27 3ff0000000000000
I/DEBUG   (  195):     d28 40f86a0000000000  d29 0000000000000001
I/DEBUG   (  195):     d30 4024000000000000  d31 4000000000000000  
...  
Force finishing activity com.blah.blah.A

这会杀死我的应用程序.

which kills my app.

推荐答案

我也遇到了此错误.抱歉,我的情况有些曲折,但万一这对这里的人有帮助,那就是:

I also experienced this error. Sorry that my scenario is a little bit meandering but in case it will help someone here it is:

我有MainActivity,它会检查Intent中的Extras以指示已收到通知.如果找到了Extras,则转到ActivityA以显示通知,您可以从中单击按钮并转到ActivityB.我使用一种方法来为我执行此检查.到目前为止一切都很好.

I have MainActivity that checks for Extras in the Intent to indicate that a Notification was received. If the Extras are found then go to ActivityA to display the Notification from which you could click a button and go to ActivityB. I used a method to do this checking for me. All good so far.

要结束ActivityB以及ActivityA,只需单击一下按钮,即可通过FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_SINGLE_TOP(注意:

To end ActivityB, along with ActivityA, from ActivityB a button click would start an Intent back to MainActivity with FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP, a la:

Intent intent = new Intent(ctx, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);

一个疏忽之处是,我在生命周期的早期还没有在MainActivity的onResume()中调用我的方法.如果在onResume()中调用getIntent(),是否仍可能返回原始的通知意图?无论如何,结果是ActivityB指向了MainActivity,然后又回到了ActivityA,因为它找到了Extras.

One oversight is that I was calling my method in onResume() of MainActivity, too early in the lifecycle for some of my calls. Is it possible the original Notification Intent may still be returned if getIntent() is called in onResume()? Anyway, the result was that ActivityB directed back to MainActivity which then went right back to ActivityA because it found the Extras.

我不确定是错误的根本原因是哪一个错误,但是如果您看到它,请考虑:

I'm not exactly sure which mistake is the root cause of the error but if you see it then consider:

  1. 您在Activity的onResume()中调用的内容在Activity生命周期中还为时过早吗?
  2. 您是否正在启动一个活动,该活动会返回到调用它的位置?

这是我的堆栈跟踪:

startActivityUncheckedLocked: task left null
                                             java.lang.RuntimeException: here
                                                 at com.android.server.am.ActivityStackSupervisor.startActivityUncheckedLocked(ActivityStackSupervisor.java:2965)
                                                 at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1935)
                                                 at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1043)
                                                 at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4069)
                                                 at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3963)
                                                 at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:159)
                                                 at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2638)
                                                 at android.os.Binder.execTransact(Binder.java:404)
                                                 at dalvik.system.NativeStart.run(Native Method)

这篇关于开始活动时获取java.lang.RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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