首页 > 解决方案 > 如何在其他活动中发送价值?

问题描述

你好,对不起我的英语我是法国人。我正在学习 Android 开发,并尝试在其他活动中发送 int 值。我已将一个 int 变量声明为 0,当我按下一个按钮时,该变量在每个按钮的其他值上变为 1。我知道如何创建一个意图,但我怎样才能让它获得我的按钮的价值。谢谢。

标签: androidandroid-intentkotlin

解决方案


这很简单。

在发送方

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是你的价值


推荐阅读