在Fragment中也可以获得返回的数据,通过在方法OnActivityResult中

嵌套Fragment情况下对二级Fragment onActivityResult()收不到Activity数据的解决方案 现象: 在做开发的时候遇到这么一个问题:在多级Fragment共同存在使用的过程当中,如果在二级Fragment跳转到一个新的Activity,并且需要Activity传返回数据的时候,一般会在该Fragment使用startActivityForResult()方法。这个时候发现,当跳转的目标Activity有回传数据的时候,该二级Fragment的onActivityResult()方法是拿 阅读详情
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.example.android.supportv4.app;


import com.example.android.supportv4.app.SendResult;
import com.example.android.supportv4.R;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;


import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;


public class FragmentReceiveResultSupport extends FragmentActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT);
        FrameLayout frame = new FrameLayout(this);
        frame.setId(R.id.simple_fragment);
        setContentView(frame, lp);


        if (savedInstanceState == null) {
            // Do first time initialization -- add fragment.
            Fragment newFragment = new ReceiveResultFragment();
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.add(R.id.simple_fragment, newFragment).commit();
        }
    }


    public static class ReceiveResultFragment extends Fragment {
        // Definition of the one requestCode we use for receiving resuls.
        static final private int GET_CODE = 0;


        private TextView mResults;


        private OnClickListener mGetListener = new OnClickListener() {
            public void onClick(View v) {
                // Start the activity whose result we want to retrieve.  The
                // result will come back with request code GET_CODE.
                Intent intent = new Intent(getActivity(), SendResult.class);
                startActivityForResult(intent, GET_CODE);
            }
        };


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }


        @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
        }


        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.receive_result, container, false);


            // Retrieve the TextView widget that will display results.
            mResults = (TextView)v.findViewById(R.id.results);


            // This allows us to later extend the text buffer.
            mResults.setText(mResults.getText(), TextView.BufferType.EDITABLE);


            // Watch for button clicks.
            Button getButton = (Button)v.findViewById(R.id.get);
            getButton.setOnClickListener(mGetListener);


            return v;
        }


        /**
         * This method is called when the sending activity has finished, with the
         * result it supplied.
         */
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            // You can use the requestCode to select between multiple child
            // activities you may have started.  Here there is only one thing
            // we launch.
            if (requestCode == GET_CODE) {


                // We will be adding to our text.
                Editable text = (Editable)mResults.getText();


                // This is a standard resultCode that is sent back if the
                // activity doesn't supply an explicit result.  It will also
                // be returned if the activity failed to launch.
                if (resultCode == RESULT_CANCELED) {
                    text.append("(cancelled)");


                // Our protocol with the sending activity is that it will send
                // text in 'data' as its result.
                } else {
                    text.append("(okay ");
                    text.append(Integer.toString(resultCode));
                    text.append(") ");
                    if (data != null) {
                        text.append(data.getAction());
                    }
                }


                text.append("\n");
            }
        }
    }
}
FCN---训练cityspaces 未经允许,不要随意转载! 最近想试试用FCN训练自己的数据集,想想标注是一件很费劲的事,于是就想到了用其他库里的数据,这里选用了cityspaces,默认已经配置好FCN. 1、下载cityspaces https://www.cityscapes-dataset.com/ 需要注册一个账号 cityspaces包含2... 阅读详情

相关推荐

【科研绘图】【数据拟合曲线】:附Origin详细画图流程

拟合曲线图

weixin_50236590的博客 4万+

android fragment返回值,android – PreferenceFragment :: onPreferenceTreeClick返回值 – 它做什么?...

调用它的代码在Preference#performClick(PreferenceScreen preferenceScreen)中,它执行以下操作:PreferenceManager preferenceManager = getPreferenceManager();if (preferenceManager != null) {PreferenceManager.OnPreferenceTr...

weixin_39872123的博客 685

手把手教你排查Abaqus中的Johnson-Cook损伤参数:避免因d3正负号导致的仿真失败

本文详细解析了Abaqus中Johnson-Cook损伤参数d3正负号设置的关键问题,帮助用户避免因参数错误导致的仿真失败和Excessive distortion报错。通过对比不同文献定义、提供实操指南和典型错误排查流程,有效提升非线性分析的准确性和效率。

weixin_33960567的博客 355

Fragment信息交互之Fragment获取DialogFragment的返回数据

Fragment信息交互会出现使用一个Fragment点击触发DialogFragment,并将信息数据返回到开始的Fragment中的情况。这种情况无法再使用startActivityforResult,所以可以使用setTargetFragment(),以及getTargetFragment().onActivityResult()的方式来进行收发数据。 ContentFragmen

小磊's blog 5820

用AI+Playwright实现零代码UI自动化测试:以登录页面为例的实战指南

本文详细介绍了如何利用AI与Playwright结合实现零代码UI自动化测试,特别以登录页面为例进行实战演示。通过自然语言描述生成测试脚本,大幅降低技术门槛,提升测试效率,并支持跨浏览器验证。适合非技术人员快速上手专业级自动化测试。

weixin_28842269的博客 402

STM32F4驱动海康工业相机实战:从PWM信号到精准触发拍照(附完整代码)

本文详细介绍了如何使用STM32F4开发板驱动海康工业相机,实现PWM信号精准触发拍照的完整方案。从硬件连接到PWM信号生成,再到相机触发配置与延迟补偿,提供了实战经验和完整代码,帮助开发者解决工业相机硬件触发中的关键问题。

weixin_33716941的博客 695

Android Studio——fragment与activity跳转返回

返回功能的几种实现方式

刘伟的博客 1788

从零开始:C#上位机集成YOLO完成摄像头目标追踪(保姆级教程)

新手入门C#上位机+YOLO做摄像头目标追踪,最忌讳的是“只抄代码,不懂逻辑”。这个教程不仅给了完整代码,还把核心原理和踩坑点都讲清楚了,新手跟着走,不仅能跑通demo,还能理解为什么这么写。如果你们在运行时遇到具体问题,比如模型导出失败、代码报错,都可以在评论区留言,我会一一解答。后续也可以出一期工业相机+YOLO目标追踪的教程,帮助大家把demo落地到实际生产中。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1030

在Fragment中OnActivityResult方法中接收Activity中返回的值

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33734785的博客 243

200Gb/s以上速率的通道信号完整性设计和优化经验(二)

为满足200Gb/s信号完整性需求,需综合优化PCB、连接器、封装及SERDES架构。关键措施包括:采用低粗糙度铜箔与低损耗材料降低传输线损耗(200G目标0.55–0.6dB/cm);通过背钻工艺控制残桩长度至4±2mil;缩减连接器焊盘残桩至600μm以内以消除谐振;封装层面推进跳层走线、低Dk/Df材料与可控SMT工艺;采用PAM4调制与基于ADC/DSP的混合信号架构实现高效均衡。先进CMOS工艺(如纳米片器件)支撑复杂数字处理,协同设计是突破速率瓶颈的核心。

小孟同学的博客 148

【DRAM存储器六十五】DDR5介绍--训练相关之MPC、Read Training Pattern、Read Preamble Training Mode

简述DDR5 MPC操作和读训练时颗粒输出pattern的配置

highman110的博客 362

Fragment的返回键 处理

新实现方式 其实我们根本不用去持有各个Fragment的实例,FragmentManager已经帮我们做了。 Activity中的有的Fragment由FragmentManager管理,Fragment嵌套的子Fragment也由FragmentManager处理,那只要拿到FragmentManager就可以用递归的方式处理了,等等,我好像发现了什么。 1、同样的先定

李某人_ 925

vue2/3 - [超详细] 实现企业微信扫码登录完整流程及代码,vue项目接入企业微信扫码登录功能教程,支持新跳页显示二维码或div容器里内嵌登录二维码(详细代码注释,一键复制开箱即用)

vue企业微信扫码登录,vue网页网站企业微信扫码登录教程,vue如何实现企业微信扫码登录功能,vue详细企业微信扫码登录功能实现,vue2实现企业微信扫码登录,前端vue企业微信扫码登录教程,vue pc电脑端企业微信扫码登录详细教程,vue项目中怎么做企业微信扫码注册登录,vue实现网站接入企业微信扫码登录,vue2做企业微信扫码登录的优质文章教程,vue网站对接企业微信扫码登录,vue企业微信扫码登录如何新开一页全屏显示登录二维码,vue企业微信登录二维码 内嵌在div容器里/跳页显示登录二维码,vu

✅ 精选推荐文章 5702

如何将数据从Activity返回到Fragment——onActivityResult

一段时间没有写了,背景是这样的:MainActivity中启动Fragment,Fragment启动OtherActivity,在OtherActivity中的数据需要返回到Fragment中。 关于数据是怎么传输的,可以看这里: 传送门:Android 学习之路 1:Activity之间传递数据的四种方式 方法其实很简单,只需要重载onActivityResult这个方法就可以了。

nomasp 4291

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

ARouter fragment onActivityResult StartActivityForResult

A_activity 的【fragment】中: @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { mItemClickBean = (ApprovalInfoRepoBean.RowsBean) adapter.getItem(position); if (...

火星男孩的分享空间 3038

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Fragment通过OnActivityResult获取Activity返回数据

Activity A 获取 Activity B 的 返回数据 直接使用startActivityForResult() 方法然后 重写 onActivityResult() 方法即可获取返回数据 然而从Fragment 跳转 Activity B 并获取返回数据时 使用getActivity().startActivityForResult()方法 在onActivityResult() 方法

Android_小菜菜的博客 2793

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Fragment.startActivityForResult不回调onActivityResult

问题 前段时间在开发中遇到一个问题,在Fragment中启动一个Activity并返回数据,但是结果并没有回调onActivityResult方法,代码很简单应该没什么问题呀。在网上查资料,都是说是因为调用activity.startActivityForResult造成的,应该fragment.startActivityForResult,试了下发现确实可以解决问题,但是原理是什么呢? 原理 我...

小久久的博客 1581

【Fragment】onActivityResult

Fragment之onActivityResult我们都知道Activity下的onActivityResult,那么fragment下的onActivityResult是否能够正确的被调用呢? Fragment->Fragment:startActivityForResult Fragment->HostCallbacks:onStartActivityFromFragment HostCa

1824

fragment中onActivityResult无法返回和在startActivityForResult调用后立即调用解决办法

以前都只是在activity中使用startActivityForResult和onActivityResult方法

小太阳的专栏 1947

Fragment中的onActivityResult问题

大家或许有遇到这个神坑,在Fragment中使用startActivityForResult能够成功,可是在Fragment中的onActivityResult却无法被调用。一不注意就让人一夜愁白了头。苦经探索(当然包括亲爱的百度和谷歌),终于总结出了一些规律。 在Fragment中使用startActivityForResult之后,onActivityResult的调用是从activi...

cmyperson的博客 631

android studio自带的NavigationUI加载的Fragment,获取Fragment对象,并在Fragment中调用onActivityResult()方法,

1. BottomNavigationView navView = findViewById(R.id.nav_view); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); //NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); navView

baidu_34816141的博客 2230

fragment无法获取onActivityResult返回的内容解决方案

fragment无法获取onActivityResult返回内容解决方案

ycqfdqy的博客 2033

Android中Fragment中onActivityResult不被调用的解决方案

android开发中,Fragment+ViewPager已经很常见了。其实遇到这个问题,其实挺尴尬的,我相信有很多小伙伴都遇到这个问题。我也在网上找了很多资料,说什么是android原生的问题,程序员偷懒了,没有处理这个事件分发等。 指钱看过这位仁兄的文章,试了试,可惜不管用。提示getParentFragment();为null 哎……放弃了。     然后我看到一个方法,但是很抱歉,忘

没花路的博客 6910

Android Fragment 的妙用 - 优雅地申请权限和处理 onActivityResult

前言 Fragment,简称碎片,可以简单地认为它就是一个“控件”,更加具体一点就是“View控制器”。它自身有生命周期。在开发中,我们经常用到,再熟悉不过了。然而,Fragment 的一些巧妙引用,不知道你是否了解过? 使用 Fragment 封装权限申请 使用 Fragment 优雅处理 onActivityResult Activity reCreate 的时候用来存储数据 这篇文章主要...

徐公,微信公众号同名 8471

fragment中onActivityResult不会调用

Activity中 public class VehicleDetailActivity extends BaseCommonActivity { private VehicleInfoDetailFragment mInfoDetailFragment; @Override protected int getContentViewId() { ret...

火星男孩的分享空间 374
上一篇: 关于FragmentPager实现Fragment的滑动切换
下一篇: 关于保存状态的Fragment,setRetainInstance(true)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值