问题
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);
this exception occurs:
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?
Thanks
EDIT 1
in my AndroidManifest.xml
file, I defined something://
to open with activity A
.
EDIT 2
when the activity A
is not singleTop
, there's no problem.
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.
回答1:
I also experienced this error. Sorry that my scenario is a little bit meandering but in case it will help someone here it is:
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.
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);
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:
- Are you calling something in onResume() of your Activity that is too early in the Activity life cycle?
- Are you starting an Activity that circles back to where it was called from?
Here is my stack trace:
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)
回答2:
In you intent, you have not set the class to start. I mean you have not defined which activity to start.
Something like this:
Intent intent = new Intent(this, newActivity.class);
or
intent.setClass(this, newActivity.class);
来源:https://stackoverflow.com/questions/21715239/getting-java-lang-runtimeexception-while-starting-an-activity