如何从子活动完成父活动 [英] How to finish parent activity from child activity

查看:124
本文介绍了如何从子活动完成父活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Andr​​oid开发。

I am new to Android development.

我已经创建了一个主要活动( - > A),其中有4个按钮。其中的4个按钮是退出键。

I have created a main Activity (->A), which has 4 buttons. One of the 4 buttons is the EXIT-button.

我开始另一项活动( - > B),上单击退出按钮的。这将打开B'Activity通过从意图A'Activity。

I start another activity (->B), on click of the EXIT-button. This opens 'B'Activity via an intent from 'A'Activity.

活动'B'包含了 - 你想退出吗?是的,按钮和放大器;无按钮。

Activity 'B' contains - Do you want to exit? Yes-Button & No-Button.

如果我给完成()的onclick按钮 - 它退出B'Activity。我要完成'B'和; 'A'。

If I give finish(), onclick of the button - it exits the 'B'Activity. I want to finish 'B' & 'A'.

我甚至试过A.finish() - >这并不得到认可,并导致语法/语义错误

I have even tried A.finish() -> this doesn't get recognized and results in syntax/semantic error.

我会在这里AP preciate帮助。

I would appreciate help here.

PS:我使用的是Android 2.2版本的手机,我不喜欢用ActivityManager来解决这个问题。

P.S : I am using Android-2.2 version phone, and I do not like to use ActivityManager to resolve this.

推荐答案

尝试推出子活性

 startActivityForResult(intent, REQUEST_EXIT);

在子活动

case R.id.quit:
     setResult(RESULT_OK, null);
     finish();

在父活动

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == REQUEST_EXIT) {
         if (resultCode == RESULT_OK) {
            this.finish();

         }
     }
}

这篇关于如何从子活动完成父活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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