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 ...
随机推荐
- java内部类细节
1 package face_09; 2 /* 3 * 为什么内部类能直接访问外部类中的成员呢? 4 * 那是因为内部类持有了外部类的引用. 外部类名.this 5 * 6 */ 7 class Ou ...
- mysql加强(3)~分组(统计)查询
一.分组(统计) 查询 1.语法 : select [distinct] *| 分组字段1[别名] [,分组字段2[别名],...] | 统计函数 from 表名 [别名] [where 条件(s)] ...
- IDEA出现Cannot resolve symbol “xxx“(无法解析符号)的解决办法
1,File->Invalidate Caches/Restart 清除缓存并重启 idea 2,检查pom文件中的依赖关系是否正确 3,maven -> Reimport 4,打开pro ...
- dp学习(二)
树和图上的dp. 4. 简单树形dp 这些是最为简单的树形dp. 一般来说,树形dp是通过子树的dp值推出当前点的dp值. 在这里,我们默认当前节点为u,它的儿子节点为v,树的根为rt. 例题4.1 ...
- springcloud 负载均衡之 ribbon。
一.什么是 ribbon? 就是负载均衡! nginx也是负载均衡 1.1 !!!!ribbon和nginx的区别是什么? /* nginx: 正向代理(和客户端连在一起) 反向代理(和服务器端连在一 ...
- 如何在pyqt中实现亚克力磨砂效果的QLabel
前言 Windows10 在 UWP 应用中支持亚克力画刷,可以在部件的底部绘制亚克力效果的背景图.下面我们使用 QLabel 来模拟这个磨砂过程. 实现方法 MSDN 文档中介绍了亚克力材料的配方, ...
- 洛谷P2240 【深基12.例1】部分背包问题(经典模板)
首先应该注意几个关键信息:装走尽多的金币.所有金币可以随意分割并且分割后金币的价值比不变; 我们可以抽象成一个买东西的场景,给你一定数目的钱,让你在这些钱内尽量在超市买更多的小零食,这就牵扯到了一个性 ...
- file类和fileinfo类的简单对比
File类:提供用于操作文件的静态方法. FileInfo类:提供操作文件的属性和实例方法. Directory类:提供用于操作目录的静态方法. DirectoryInfo类:提供用于操作目录的实例方 ...
- JAVA char类型
char类型表示的是单个字符类型,任何数据使用单引号括起来的都是表示字符.字符只能有一个字符. 注意:特殊字符的转义序列:转义字符 转义字符的概述: 特殊字符使用"\"把其转化成字 ...
- CSS样式表的书写位置
行内式(内联样式) 是通过标签的style属性来设置元素的样式,其基本语法格式如下: <标签名 style="属性1:属性值1; 属性2:属性值2; 属性3:属性值3;"&g ...