Scenario
Activity A (login) starts activity B then finish();
Activity B calls startActivityForResult(Activity C)
Activity C runs nicely, then exits after choosing a phone number (as it should)
— Back to the desktop (app stops)!
Why didn’t it get back to Activity B’s onActivityResult()?
Notes
I have created the proper onActivityResult() on activity B.
I have searched and read every shred of data on stackoverflow about startActivityForResult.
Code Slips
The code which starts Activity B:
ComponentName component = new ComponentName("com.emobiletelecom", PokeTALK.class.getName());
Intent intent = new Intent();
intent.setComponent(component);
startActivity(intent);
finish();
The code which starts Activity C:
startActivityForResult(new Intent(this, ContactsPickerActivity.class), 2007);
The code finishing Activity C:
Intent intent = new Intent();
intent.putExtra(KEY_PHONE_NUMBER, contactNumber);
setResult(RESULT_OK, intent);
finish();
enter code here
LOG
04-23 16:32:27.382: I/ActivityManager(28158): START
{cmp=com.emobiletelecom/com.codinguser.android.contactpicker.ContactsPickerActivity} from pid 30108
04-23 16:32:27.392: W/WindowManager(28158): Failure taking screenshot for (180x300) to layer 21010
04-23 16:32:27.432: V/PokeTALK(30108): onPause
04-23 16:32:27.642: I/WindowManager(28158): createSurface Window{415eefe8 com.emobiletelecom/com.codinguser.android.contactpicker.ContactsPickerActivity paused=false}: DRAW NOW PENDING
04-23 16:32:27.812: V/PhoneStatusBar(28212): setLightsOn(true)
04-23 16:32:28.042: I/ActivityManager(28158): Displayed com.emobiletelecom/com.codinguser.android.contactpicker.ContactsPickerActivity: +599ms
04-23 16:32:28.192: V/PT(30108): onStop - PokeTALK
04-23 16:33:00.292: D/dalvikvm(28212): GC_CONCURRENT freed 396K, 36% free 10580K/16391K, paused 14ms+8ms
04-23 16:33:24.102: D/dalvikvm(30108): GC_FOR_ALLOC freed 189K, 6% free 12032K/12679K, paused 52ms
04-23 16:33:24.122: I/dalvikvm-heap(30108): Grow heap (frag case) to 13.159MB for 1390096-byte allocation
04-23 16:33:24.232: D/dalvikvm(30108): GC_CONCURRENT freed 33K, 6% free 13355K/14087K, paused 4ms+4ms
04-23 16:33:24.341: D/dalvikvm(30108): GC_FOR_ALLOC freed 0K, 6% free 13356K/14087K, paused 34ms
04-23 16:33:24.351: I/dalvikvm-heap(30108): Grow heap (frag case) to 14.452MB for 1390096-byte allocation
04-23 16:33:24.522: D/dalvikvm(30108): GC_CONCURRENT freed <1K, 6% free 14713K/15495K, paused 18ms+5ms
04-23 16:33:27.342: W/WindowManager(28158): Failure taking screenshot for (180x300) to layer 21015
04-23 16:33:27.392: W/NetworkManagementSocketTagger(28158): setKernelCountSet(10005, 1) failed with errno -2
04-23 16:33:27.442: I/WindowManager(28158): createSurface Window{41614cd0 com.android.launcher/com.android.launcher2.Launcher paused=false}: DRAW NOW PENDING
04-23 16:33:27.532: W/InputManagerService(28158): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@413fbdb0 (uid=10040 pid=30108)
04-23 16:33:28.292: W/NetworkManagementSocketTagger(28158): setKernelCountSet(10040, 0) failed with errno -2
I believe
finishFromChild()is where activity B is being accidentally closed.finishFromChild()is called when the child activity (C in this hypothetical) callsfinish(). So this command might be the one closing activity B when you don’t mean to.