Tools for tracing calls to onActivityResult

2019-08-15 03:26发布

问题:

What tools (log files, traces, etc) exist to debug calls to onActivityResult? The Android documentation says that

onActivityResult is called when an activity you launched exits, giving you the requestCode you started it with, the resultCode it returned, and any additional data from it. The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.*

I'm trying to debug a case where apparently none of those conditions are met - onActivityResult is being called immediately without the target activity ever being involved (according to breakpoints I set in it). The stack trace looks like this:

DGraphActivity.onActivityResult(int, int, Intent) line: 107 
DGraphActivity(Activity).dispatchActivityResult(String, int, int, Intent) line: 3908    
ActivityThread.deliverResults(ActivityThread$ActivityClientRecord, List) line: 2532 
ActivityThread.handleSendResult(ActivityThread$ResultData) line: 2578   
ActivityThread.access$2000(ActivityThread, ActivityThread$ResultData) line: 117 
ActivityThread$ResultData(ActivityThread$H).handleMessage(Message) line: 965    
ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 130 
ActivityThread.main(String[]) line: 3687    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 842  
ZygoteInit.main(String[]) line: 600 
NativeStart.main(String[]) line: not available [native method]

The target Activity is called AddCommentActivity, which, as you can see, is not referenced in the stack trace. AddCommentActivity DOES get called just fine AFTER onActivityResult.

N.B. This is NOT a duplicate of my other question onActivityResult being called instantly That one is to ask for a solution or workaround to the specific problem. This one is to ask about tools and strategies for this class of problems in general.