当前位置:网站首页>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
边栏推荐
- Sword finger offer 07 Rebuild binary tree
- Prototype mode
- SQL最常用的语句
- 基于深度Q学习的雅达利打砖块游戏博弈
- Mt60b1g16hc-48b:a micron memory particles FBGA code d8bnk[easy to understand]
- Golang regular regexp package uses -05- extend expand(), cut split() according to the rule
- 解析数仓lazyagg查询重写优化
- 镁光256Gb NAND Flash芯片介绍
- Sword finger offer 10- I. Fibonacci sequence
- GO语言-锁操作
猜你喜欢

Based on neural tag search, the multilingual abstracts of zero samples of Chinese Academy of Sciences and Microsoft Asiatic research were selected into ACL 2022
Why is it said that restarting can solve 90% of the problems
Take you to the open source project of smart home: the preliminary configuration of zhiting home cloud and home assistant+ homebridge

通俗讲跨域

VectorDraw Developer Framework 10.1001 Crack
MySQL installation tutorial
Introduction to database transactions

Sword finger offer 05 Replace spaces

Continuous integration of aspnetcore & cloud flow
Desktop development (Tauri) opens the first chapter
随机推荐
Traversal and branch judgment of JS (case on June 24, 2022)
Multithreading, parallelism, concurrency, thread safety
李飞飞团队将ViT用在机器人身上,规划推理最高提速512倍,还cue了何恺明的MAE
Pytest测试框架笔记
What is the NFT digital collection?
[issue 24] one year experience of golang to develop futu
Sword finger offer 07 Rebuild binary tree
Leetcode topic [array]-34- find the first and last positions of elements in a sorted array
合宙Air32F103CBT6開發板上手報告
MySQL installation tutorial
iVX低代码平台系列详解 -- 概述篇(一)
什么是oa
Constructor Pattern
Sword finger offer 04 Find in 2D array
Message format of Modbus (PLC)
Don't underestimate the integral mall, its role can be great!
Uniapp converts graphic verification codes in the form of file streams into images
Sword finger offer II 091 Paint the house
商城风格也可以很多变,DIY 了解一下!
The style of the mall can also change a lot. DIY can learn about it!