当前位置:网站首页>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
边栏推荐
- 有哪些新手程序员不知道的小技巧?
- Go development team technical leader Russ Cox sends a document to share go's version control history
- Golang uses Mongo driver operation - increase (Advanced)
- Consumer and producer cases of inter thread synchronization (condition variable)
- 数据类型的内置方法
- 深度学习 pytorch cifar10数据集训练「建议收藏」
- f_read 函数[通俗易懂]
- Resolve Visio and office365 installation compatibility issues
- MySQL modify field statement
- 读配置、讲原理、看面试真题,我只能帮你到这了。。。
猜你喜欢

Alvaria宣布客户体验行业资深人士Jeff Cotten担任新首席执行官

appium服务的启动与关闭踩坑记录

一行代码可以做什么?

Sword finger offer 07 Rebuild binary tree

Do you want to go to an outsourcing company? This article will give you a comprehensive understanding of outsourcing pits!
Create raspberry PI image file of raspberry pie

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

Popular cross domain

读配置、讲原理、看面试真题,我只能帮你到这了。。。

Read the configuration, explain the principle and read the interview questions. I can only help you here...
随机推荐
不要小看了积分商城,它的作用可以很大!
JS的注释
Sleep formula: how to cure bad sleep?
Mt60b1g16hc-48b:a micron memory particles FBGA code d8bnk[easy to understand]
Startup and shutdown of appium service
Yadali brick playing game based on deep Q-learning
js 给元素添加自定义属性
Jz-065 path in matrix
Pytest test framework notes
Time wheel and implementation analysis of time wheel in go zero
Go development team technical leader Russ Cox sends a document to share go's version control history
AutoK3s v0.5.0 发布 延续简约和友好
Sword finger offer 07 Rebuild binary tree
TFIDF and BM25
Prototype mode
Classic deadlock scenario of multithreading and its solution (philosopher dining problem)
How to reload the win10 app store?
MySQL修改字段語句
Principle analysis of ThreadLocal source code
合宙Air32F103CBT6开发板上手报告