android - 如何在其他活动中发送价值?
问题描述
你好,对不起我的英语我是法国人。我正在学习 Android 开发,并尝试在其他活动中发送 int 值。我已将一个 int 变量声明为 0,当我按下一个按钮时,该变量在每个按钮的其他值上变为 1。我知道如何创建一个意图,但我怎样才能让它获得我的按钮的价值。谢谢。
解决方案
这很简单。
在发送方
int intValue
= 从编辑文本或按钮中获取值
用于Intent.putExtra
设置值
Intent myIntent = new Intent(test1.this, test2.class);
myIntent.putExtra("yourname", intValue);
startActivity(myIntent);
在接收方
用来Intent.getIntExtra
获取价值
Intent mIntent = getIntent();
int intValue = mIntent.getIntExtra("yourname", 0);
intValue
是你的价值
推荐阅读
- android - 使用 Terraform 创建 AWS Amplify 资源
- python - 正弦函数 - Python
- webpack - eslint-webpack-plugin 输出格式错误
- java - 关于随机(x)和随机()%x的数学问题 - Java
- docker - 我可以在没有 bash 脚本的情况下使用 docker-compose 来检查容器,然后将文件从容器复制到主机吗?
- image-processing - 如何对二维码中的某些像素实施约束?
- jasperserver - Jasper 服务器“不支持融合组件”渲染 PDF
- c++ - 类型别名在类中有什么作用?
- sql - 一年无记录后的新纪录
- python - 在 Python 中从 3 元素元组创建字典 - TypeError