为了账号安全,请及时绑定邮箱和手机立即绑定

如何在单击按钮上启动新活动

如何在单击按钮上启动新活动

开心每一天1111 2019-06-01 11:38:37
如何在单击按钮上启动新活动在Android应用程序中,当单击另一个活动中的按钮时,如何启动新活动(GUI),以及如何在这两个活动之间传递数据?
查看完整描述

3 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

创建ViewPerson活动的意图并传递PersonId(例如,用于数据库查找)。

Intent i = new Intent(getBaseContext(), ViewPerson.class);                      i.putExtra("PersonID", personID);startActivity(i);

然后,在ViewPerson活动中,您可以获得额外的数据包,确保它不是NULL(如果有时不传递数据的话),然后获取数据。

Bundle extras = getIntent().getExtras();if(extras !=null){
     personID = extras.getString("PersonID");}

现在,如果需要在两个活动之间共享数据,也可以使用GlobalSingleton。

public class YourApplication extends Application {     
     public SomeDataClass data = new SomeDataClass();}

然后在任何活动中调用它:

YourApplication appState = ((YourApplication)this.getApplication());appState.data.CallSomeFunctionHere();
 // Do whatever you need to with data here.  Could be setter/getter or some other type of logic


查看完整回答
反对 回复 2019-06-01
  • 3 回答
  • 0 关注
  • 493 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号