通过在Android中Java的传递的双精度值到不同类 [英] Passing a double value through to a different class in Android Java
问题描述
我只是想知道什么样的方式有通过从ClassA的两个或两个以上的双值ClassB的
I am just wondering what ways there are to pass two or more double values from classA to ClassB
在一分钟我已经找到code,让我这个方法:
at the minute i have found code that give me this method:
double a, b;
double a = 2.456;
double b = 764.2353;
Intent i = new Intent();
i.setClassName("com.b00348312.application","com.b00348312.application.ClassB");
double number = getIntent().getDoubleExtra("value1", a);
double number = getIntent().getDoubleExtra("value2", b);
startActivity(i);
这不通过的值,也可以找到检索这些值的方法
This does not pass the values through nor can i find a way of retrieving these values
在这里还有一个问题提出创建类的实例,但在尝试,我似乎无法通过正确地传递价值的方法。
Another question on here suggested the method of creating an instance of the class but trying that i cant seem to pass the values through properly.
我编程的机器人,所以我不知道是否该方法会有所不同。
I am programming for Android, so I don't know if the method will be different
推荐答案
您实际上并没有把你的双打到意图
You're not actually placing your doubles into your Intent
Intent yourInent = new Intent(thisActivity.this, nextActivity.class);
Bundle b = new Bundle();
b.putDouble("key", doubleVal);
yourIntent.putExtras(b);
startActivity(yourIntent);
然后,把它在你的下一个活动:
Then, get it in your next Activity:
Bundle b = getIntent().getExtras();
double result = b.getDouble("key");
这篇关于通过在Android中Java的传递的双精度值到不同类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!