是否可以将按钮的状态保存在一个活动中,然后将其传递给新活动? [英] Is it possible to save the state of a button in one activity and then pass it on to a new activity?

查看:53
本文介绍了是否可以将按钮的状态保存在一个活动中,然后将其传递给新活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题几乎总结了我想做的事情.

My question pretty much sums up what I want to do.

我的想法是,如果让我们说(按下来自活动A的按钮1)并且加载了活动B,我想将按钮1的状态(是否按下)传递给活动B,并且我想对它进行一些操作.例如:

My idea is if lets say (button 1 from activity A is pressed) and activity B is loaded I want to pass in activity B the state of button 1 (pressed or not) and I want to do something with it. For example:

if(button1.isChecked())
{
     //do something
}

推荐答案

在第一个活动中,您可以使用:

In the first activity, you can use:

Intent intent = new Intent(this, Your 2nd Activity.class);
intent.putExtra("buttonStatus", "you button status true or false");
 startActivity(intent);

,在oncreate内的第二个活动中,您将使用:

and in the 2nd activity inside oncreate, you will use:

boolean getButtonStatus = getIntent().getBooleanExtra("buttonStatus", false);

这篇关于是否可以将按钮的状态保存在一个活动中,然后将其传递给新活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆