如何取得父标签活动的子活动的结果呢? [英] How to get result of child activities in a parent tab activity?

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

问题描述

我有活性2,它是具有子活动Activity3和Activity4.Acticity2一个TabActivity被称为从Activity1.I想对这款从子活动的结果(Activity3或Activity4)在Activity2.Any帮助...?

I have Activity2 which is a TabActivity having child activities Activity3 and Activity4.Acticity2 is called from Activity1.I want results from child activity(Activity3 or Activity4) in Activity2.Any help on this...?

推荐答案

  • 使用 startActivityForResult 而不是 startActivity 启动Activity3和Activity4。
  • 使用的setResult 在你的孩子的活动将数据返回到predecessor活动
  • 使用 onActivityResult 在父活动的子活动收到的结果

  • Use startActivityForResult instead of startActivity to start Activity3 and Activity4.
  • Use setResult in your child activity to return data to the predecessor activity
  • Use onActivityResult in your parent activity to receive the result from the child activity
  • 编辑:添加了捆绑信息。保持原来的答案,因为它很可能会为别人有用。

    Added bundle information. Keeping original answer as it will likely be useful for others.

    既然你实际上并没有开始与 startActivity 的活动,您将需要从孩子的活动存储数据,试试这个:

    Since you aren't actually starting the activity with startActivity, you will need to store your data from the child activities, try this:

    在TabActivity:

    In TabActivity:

    // putExtra is overloaded so you can add almost any kind of data.
    // First parameter is the key, second is the value
    getIntent().putExtra ( "Result", "OK" );
    

    在父活动:

    // tabAct is the TabActivity object for your tab
    // Here, just specify the key that you used in putExtra in your TabActivity
    String actResult = tabAct.getStringExtra ( "Result" );
    if ( actResult.equals ( "OK" ) {
        // Do your actions for success
    }
    else {
        // Do your actions for failure
    }
    

    这篇关于如何取得父标签活动的子活动的结果呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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