从较新的活动返回时,如何在旧的活动上触发功能? [英] How to trigger a function on a old Activity when returning from a newer activity?

查看:49
本文介绍了从较新的活动返回时,如何在旧的活动上触发功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在从较新的活动返回时触发有关旧活动的事件.

i am wanting to Trigger a event on the old activity when returning back from the newer activity.

因此,当我按下完成"按钮并使用Finish();即时通讯返回到旧活动时,此方法有效,但我需要在旧活动上更新ui. 我要设置OnActivityResultListener吗?并以这种方式处理?我不确定该如何设置,但我不确定其他方面有很多信息.

so when i hit the Done button and im using Finish(); to return back to the old Activity this works but i need to update the ui on the old activity. do i set up for a OnActivityResultListener? and handle it that way? im not exactly sure how to set that up but im sure there is plenty of info on that else were.

推荐答案

您应使用以下方法开始活动

You should use below method to start your activity

static final int YOUR_REQUEST_CODE = 1;  // The request code
startActivityForResult(yourIntent, YOUR_REQUEST_CODE);

然后,在 OLD 活动中,覆盖以下方法:

And then, in the OLD activity, override below method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == YOUR_REQUEST_CODE) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {

            // Do something with here.
        }
    }
}

更多详细信息,请参见 Android开发人员官方指南

More details can be found at Android Developer Official Guide

这篇关于从较新的活动返回时,如何在旧的活动上触发功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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