使用整数,字符串的其他活动等 [英] Using Integers, Strings etc in other Activities

查看:135
本文介绍了使用整数,字符串的其他活动等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动。在一个我计算了一些东西,所以我有一些整数,也有一些字符串存储。所以,现在我想在我的第二个活动中使用这些蜇伤和整数。如何在我在第二次活动使用它们?

I've got two Activities. In one I calculate some things and therefore I have some Integers and also some Strings stored. So now I would like to use these Stings and Integers in my second Activity. How an I use them in my second Activity?

感谢

推荐答案

您得把它们传递给你的第二个活动。

You gotta pass them to your second activity.

当您创建意图开始活动

Intent i = new Intent(FirstActivity.this, SecondActivity.class);

做额外的步骤是这样

do extra step like this

i.putExtra("integer", myInteger); //where myInteger is integer you have in first Activity
i.putExtra("string", myString); //where myString is String you have in first Activity

startActivity(i);

和现在的第二个活动来访问这些值使用以下code

and now in second Activity to access those values use following code

int in = this.getIntent().getExtras().getInt("integer");
String str = this.getIntent().getExtras().getString("string");

就这么简单。

这篇关于使用整数,字符串的其他活动等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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