如何启动按钮点击新活动 [英] How to start new activity on button click
本文介绍了如何启动按钮点击新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个Android应用程序,你如何开始一个新的活动(GUI)点击在另一活动按钮时,你怎么这两项活动之间传递数据?
In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?
推荐答案
容易。 [重新排序]
Easy. [Re-ordered]
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
myIntent.putExtra("key", value); //Optional parameters
CurrentActivity.this.startActivity(myIntent);
附加功能是通过检索的另一面:code编辑]
Extras are retrieved on the other side via: [code edited]
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String value = intent.getStringExtra("key"); //if it's a string you stored.
[添加] 不要忘了添加新的活动在AndroidManifest.xml:
[added] Don't forget to add your new activity in the AndroidManifest.xml:
<activity android:label="@string/app_name" android:name="NextActivity"/>
这篇关于如何启动按钮点击新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文