在Android的活动之间传递数据 [英] Passing data between activities in Android

查看:125
本文介绍了在Android的活动之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何通过在Android应用程序活动之间的数据?

How do you pass data between activities in an Android application?

推荐答案

在你当前活动,创建一个意图

in your current activity, create an intent

Intent i = new Intent(getApplicationContext(), ActivityB.class);
i.putExtra(key, value);
startActivity(i);

然后在其他活动中,检索这些值。

then in the other activity, retrieve those values.

Bundle extras = getIntent().getExtras(); 
if(extras !=null) {
    String value = extras.getString(key);
}

这篇关于在Android的活动之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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