startActivityForResult启动退出应用程序的第二个活动

时间:2012-04-23 16:31:25

标签: android android-activity activity-lifecycle

方案

活动A(登录)启动活动B,然后结束();

活动B调用startActivityForResult(活动C)

活动C运行良好,然后在选择电话号码后退出(应该这样)

- 返回桌面(app停止)!

为什么不回到活动B的onActivityResult()?

备注

我在活动B上创建了正确的onActivityResult()。

我搜索并阅读了有关startActivityForResult的stackoverflow上的每一个数据。

代码单

启动活动B的代码:

ComponentName   component   = new ComponentName("com.emobiletelecom", PokeTALK.class.getName());
    Intent          intent      = new Intent();
    intent.setComponent(component);
startActivity(intent);
    finish();

启动活动C的代码:

startActivityForResult(new Intent(this, ContactsPickerActivity.class), 2007);

完成活动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

2 个答案:

答案 0 :(得分:1)

I call finish() on the following methods: onStop(), onKeyDown(back key clicked), finishFromChild()

我相信finishFromChild()是活动B意外关闭的地方。当子活动(此假设中的C)调用finishFromChild()时,将调用finish()。所以这个命令可能是你不想要的一个结束活动B.

答案 1 :(得分:0)

当您启动活动C时,不应该在活动B内调用finish()。活动B必须坚持从活动C接收结果。