当前位置:网站首页>Activation and value transfer of activity
Activation and value transfer of activity
2022-06-25 16:00:00 【Crazy D black bull】
Activity Start of
①. stay Android The communication between components in the application uses Intent. One Activity adopt Intent To express your “ Intention ”.
②. There are usually two ways :
- Intent intent = new Intent(MainActivity.this , NextActivity.class);
- Intent intent = new Intent();
- intent.setClass(MainActivity.this , NextActivity.class);
③. There are two common startup methods :
- startActivity();
- startActivityForResult();// Use... When you need to return data
Activity Jump and exchange data between :
① The data is transferred to the next page
from MainActivity Jump to FirstActivity The code is as follows
Intent intent =new Intent(MainActivity.this,FirstActivity.class);
// Pass string
intent.putExtra("value1"," I'm from MainActivity The data that came in ");
intent.putExtra("value2",100);// Pass integer
startActivity(intent);
//HashMap<String,String> map=new HashMap<String,String>();
//map.put("aaa"," I am a aaa");
//map.put("dddd"," I am a ddd");
//Intent intent2 =new Intent(MainActivity.this,FirstActivity.class);
//intent2.putExtra("map",map);// If it is javabean be bean Need to serialize
//startActivity(intent2);
stay FirstActivity Data received in
String str= intent.getStringExtra("value1");
int intValue= intent.getIntExtra("value2",0);
② Data back (SecondActivity Return data to MainActivity)
MainActivity Middle jump
Intent intent2 = new Intent(MainActivity.this, SecondActivity.class);
startActivityForResult(intent2, 1111);rewrite onActivityResut receive data
if (requestCode == 1111) {// And jumping requestCode Corresponding
if(resultCode==RESULT_OK)
{
String str= data.getStringExtra("str");
mTextView3.setText(str);
}
}SecondActivity Set data in
Intent intent=new Intent();
intent.putExtra("str"," I am a SecondActivity Data returned from ");
setResult(RESULT_OK,intent);
finish();
Download resources
边栏推荐
- Advanced SQL statement 1 of Linux MySQL database
- Uncover gaussdb (for redis): comprehensive comparison of CODIS
- Optimization of lazyagg query rewriting in parsing data warehouse
- 镁光256Gb NAND Flash芯片介绍
- leetcode-8. 字符串转换整数 (atoi)
- 不要再「外包」AI 模型了!最新研究发现:有些破坏机器学习模型安全的「后门」无法被检测到
- leetcode-8. String to integer (ATOI)
- 商城风格也可以很多变,DIY了解一下!
- Open the box to experience rust, come on!!!
- Sword finger offer 07 Rebuild binary tree
猜你喜欢

合宙Air32F103CBT6开发板上手报告

10款超牛Vim插件,爱不释手了

分享自己平时使用的socket多客户端通信的代码技术点和软件使用

Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's MAE

Geographic location data storage scheme - redis Geo
Golang open source streaming media audio and video network transmission service -lal

golang使用mongo-driver操作——增(进阶)

教务系统开发(PHP+MySQL)
Consumer and producer cases of inter thread synchronization (condition variable)
Cloning and importing DOM nodes
随机推荐
免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!
TensorFlow加载cifar10数据集
Go development team technical leader Russ Cox sends a document to share go's version control history
Constructor Pattern
Uniapp converts graphic verification codes in the form of file streams into images
[golang] leetcode intermediate - find the first and last position of an element in a sorted array & Merge interval
leetcode-8. 字符串转换整数 (atoi)
地理位置数据存储方案——Redis GEO
Lecun predicts AgI: big model and reinforcement learning are both ramps! My "world model" is the new way
Sword finger offer II 091 Paint the house
js 给元素添加自定义属性
普通人的2022春招总结(阿里、腾讯offer)
Continuously improve the overall performance of adaoracle Oracle Oracle
Native JS dynamically add elements
MySQL修改字段語句
分享自己平时使用的socket多客户端通信的代码技术点和软件使用
异步处理容易出错的点
What are the reasons why the game industry needs high defense servers?
元宇宙系统的概念解析
李飞飞团队将ViT用在机器人身上,规划推理最高提速512倍,还cue了何恺明的MAE