startActivityForResult跳转后回调数据
从AActivity向BActivity跳转后,关闭BActivity并向AActivity回调一些数据:
建立AActivity.java文件:
1 public class AActivity extends AppCompatActivity {
2 private Button btnJump;
3 @Override
4 protected void onCreate(Bundle savedInstanceState) {
5 super.onCreate(savedInstanceState);
6 setContentView(R.layout.activity_aactivity);
7 btnJump=findViewById(R.id.jump);
8 btnJump.setOnClickListener(new View.OnClickListener() {
9 @Override
10 public void onClick(View view) {
11 //数据传递
12 Intent intent=new Intent(AActivity.this,BActivity.class);
13 Bundle bundle=new Bundle();
14 bundle.putString("name","霉霉");
15 bundle.putInt("age",30);
16 intent.putExtras(bundle);
17 //返回数据
18 startActivityForResult(intent,0);//向BActivity跳转
19
20 }
21 });
22 }
23
24 @Override
25 protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
26 super.onActivityResult(requestCode, resultCode, data);
27 Toast.makeText(AActivity.this, data.getExtras().getString("title"), Toast.LENGTH_SHORT).show();
28 }//接收BActivity回调的数据
29 }
对应的activity_aactivity.xml文件为:
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="match_parent"
3 android:layout_height="match_parent"
4 android:orientation="vertical"
5 android:padding="20dp">
6
7 <Button
8 android:id="@+id/jump"
9 android:layout_width="match_parent"
10 android:layout_height="50dp"
11 android:text="jump"
12 android:textAllCaps="false"/>
13 </LinearLayout>
建立BActivity.java文件:
1 public class BActivity extends AppCompatActivity {
2 private TextView TVtitle2;
3 private Button btnFinish;
4 @Override
5 protected void onCreate(Bundle savedInstanceState) {
6 super.onCreate(savedInstanceState);
7 setContentView(R.layout.activity_bactivity);
8 TVtitle2=findViewById(R.id.tv_title2);
9 btnFinish=findViewById(R.id.btn_finish);
10
11 Bundle bundle=getIntent().getExtras();
12 String name=bundle.getString("name");
13 int age=bundle.getInt("age");//传递数据
14
15 TVtitle2.setText(name+":"+age);
16
17 btnFinish.setOnClickListener(new View.OnClickListener() {
18 @Override
19 public void onClick(View view) {
20 Intent intent=new Intent();
21 Bundle bundle1=new Bundle();
22 bundle1.putString("title","I'm back!!");
23 intent.putExtras(bundle1);
24 setResult(Activity.RESULT_OK,intent);
25 finish();//关闭BActivity文件并回调数据
26 }
27 });
28 }
29 }
对应的activity_bactivity.xml文件:
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="match_parent"
3 android:layout_height="match_parent"
4 android:orientation="vertical"
5 android:padding="20dp">
6 <TextView
7 android:id="@+id/tv_title2"
8 android:layout_width="wrap_content"
9 android:layout_height="wrap_content"
10 android:textColor="@color/black"
11 android:textSize="20sp"
12 android:layout_margin="20dp" />
13
14 <Button
15 android:id="@+id/btn_finish"
16 android:layout_width="match_parent"
17 android:layout_height="wrap_content"
18 android:text="点我回调数据"/>
19 </LinearLayout>
startActivityForResult跳转后回调数据的更多相关文章
- jsp 页面跳转后修改数据,返回时不更新
项目jsp页面上用隐藏input框接收获取数据,在跳转入另一页面前,js操作修改数据,但返回时发现无效. 需求是点击抽奖后机会减少一次,但是当做跳转操作后返回时,次数有缓存问题 jsp: <in ...
- model,map,MapAndVivew用于页面跳转时候使用的即跳转后才添加属性 这样再回调中无法使用 因为回调的前提是页面不调转;解决的方法是用responsewrite(普通的字符响应)
model,map,MapAndVivew用于页面跳转时候使用的即跳转后才添加属性 这样再回调中无法使用 因为回调的前提是页面不调转:解决的方法是用responsewrite
- 利用js对象将iframe数据缓存, 实现子页面跳转后, 返回时不丢失之前填写的数据
利用js对象将iframe数据缓存, 实现子页面跳转后, 返回时不丢失之前填写的数据 实现描述:将数据存放在js对象中, 然后放在父页面的document对象中, 在页面刷新的时候将父页面的值取出来, ...
- Android Activity间跳转与传递数据
1 概述 Activity之间的跳转主要使用 startActivity(Intent intent); startActivityForResult(Intent intent,int reques ...
- Intent界面跳转与传递数据
Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据. intent可以激活Activity,服务,广播三类组件. 本博文讲的是显示意图激活Activity组件 ...
- 获取经过跳转后的url地址
粗略一算,不写code已经好几个月了. 昨日受兄弟所托,为他写了一个小小的程序. 程序功能: 自动获取跳转后的Url地址 如下图所示: (newUrl.txt为转换后的地址信息...) 实现过程: 每 ...
- Android基础之——startActivityForResult启动界面并返回数据,上传头像
在android应用的开发过程中,常常会出现启动一个界面后填写部分内容后带着数据返回启动前的界面,最典型的应用就是登录过程.在非常多应用程序的模块中,都有"我的"这个模块,在未登录 ...
- 解决微信小程序使用switchTab跳转后页面不刷新的问题
wx.switchTab({ url: '../index/index', success: function(e) { var page = getCurrentPages().pop(); if ...
- FFMPEG结构体分析:AVFrame(解码后的数据)
https://blog.csdn.net/jxcr1984/article/details/52766524 本文转自: http://blog.csdn.net/leixiaohua1020/ar ...
随机推荐
- 集合框架-ListIterator接口
1 package cn.itcast.p4.list.demo; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 imp ...
- Rsync安装配置
一.先准备两台CentOS服务器,假定是 1.172.18.2.225(服务端) 需要配置rsyncd.conf文件 2.172.18.2.227(客户端) 不需要配置rsyncd.conf文件 二. ...
- Python如何把八进制转换成ASCII码
做题途中拿到一串八进制字符串 0126 062 0126 0163 0142 0103 0102 0153 0142 062 065 0154 0111 0121 0157 0113 0111 010 ...
- elasticsearch查询之大数据集分页查询
一. 要解决的问题 search命中的记录特别多,使用from+size分页,直接触发了elasticsearch的max_result_window的最大值: { "error" ...
- [免费下载应用]iNeuKernel.Ocr 图像数据识别与采集原理和产品化应用
目 录 1..... 应用概述... 2 2..... 免费下载试用... 2 3..... 视频介绍... 2 4..... iNeuLink.Ocr图像数据采集应用... 2 5... ...
- 模仿UIApplication单例
要求:程序一启动就创建创建对象.创建的对象只能通过share的⽅方式获取对象.不能够进行alloc 操作,当执⾏行alloc时, 程序发生崩溃 1.程序一启动的时候就创建对象.当类被加载到内存的时候就 ...
- [转]API性能测试基本性能指标及要求
原文链接http://blog.csdn.net/strawbingo/article/details/46458959 指标的基本概念 1.事务(Transaction) 在web性能测试中,一个事 ...
- 自定义滚动条样式-兼容IE
滚动条样式设置 html部分: 1 <div id="scroll" style="width: 500px; height: 300px; border: 2px ...
- LeetCode随缘刷题之Java经典面试题将一个字符串数组进行分组输出,每组中的字符串都由相同的字符组成
今天给大家分享一个Java经典的面试题,题目是这样的: 本题是LeetCode题库中的49题. 将一个字符串数组进行分组输出,每组中的字符串都由相同的字符组成 举个例子:输入["eat&qu ...
- async同步异步
1.同步:var async = require("async"); async.series([step1, step2, step3],function(err, values ...