从一个类中的另一个Android使用整数 [英] Using integer from one class in another Android

查看:169
本文介绍了从一个类中的另一个Android使用整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,用另一个从一个活动的整数。

I need some help with using integer from one activity to another.

我做一些基本的数学程序(游戏)。它得到两个随机数,随机算,30秒之多,可以解决数学问题。

I am making some basic math program(game). It gets two random numbers, random operator, and 30 secs to solve math problems as much as you can.

如果你解决问题u得到1分。

If you solve problem u get 1 point.

现在不管怎样,我想获得该用户取得的点数,并呼吁其他活动使用 * RankActivity *。

Anyway right now, I want to get number of points that user have made and use it in another activity called *RankActivity*.

主要活动是名为 * BrzoRacunanjeActivity * ,它包含按钮和一个 *为int * 名为 * poenibrojanje * 这获得积分用户发了,当我点击按钮,它会打开新的活动这一行的行号:

Main activity is called *BrzoRacunanjeActivity* and it contains button and one *int* called *poenibrojanje* which get number of points that user have made, and when I click on button, it opens new Activity with this line:

startActivity(new Intent(this, RankActivity.class));

正如你可以看到另一个活动被称为RankActivity,并有我写的:

As you can see another Activity is called RankActivity, and there I wrote :

*BrzoRacunanjeActivity a1 = new BrzoRacunanjeActivity();*

*System.out.println("Number of points:" + a1.poenibrojanje);;*

和我得到的所有时间这个 reuslt:9月9日至22日:09:14.940:信息/的System.out(289):点数:0

and I get all time this reuslt: 09-22 09:09:14.940: INFO/System.out(289): Number of points:0

推荐答案

首先使
 像静态变量公共静态INT poenibrojanje;
 在你的 BrzoRacunanjeActivity.class 文件现在您可以在任何其他的类使用这个变量作为像

first of all make static variable like as public static int poenibrojanje; in your BrzoRacunanjeActivity.class file now you can use this variable in any other class like as

 BrzoRacunanjeActivity.poenibrojanje

也可以使用 putExtras();

在您的主要活动。

Intent i = new Intent(this, RankActivity.class);
i.putExtra("Value",poenibrojanje);

在你的下一个活动。

int v = (getIntent().getExtras().getInt("Value")) ;

这篇关于从一个类中的另一个Android使用整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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