android studio - 在活动之间移动浮动

android studio - moving float between activitys

您好,我已经尝试了一些有意在 activity 之间移动浮点值的方法,但它对我不起作用,因为该值会重新启动。

我的代码:

第一个activity:

Intent myIntent1 = new Intent(first.this, second.class);
                String s=Float.toString(selectedSpeed);
                myIntent1.putExtra("speed", s);

秒activity:

String speed1=getIntent().getStringExtra("speed");
    float s=Float.parseFloat(speed1);

float 的值始终为 0,应用程序在 "second activity".

的第二行出现编译错误

感谢帮手!

试试这个:

Activity 1

Bundle b = new Bundle();
b.putFloat("speed1", FloatVal);
yourIntent.putExtras(b);
startActivity(yourIntent);

Activity 2

Bundle bundle = getIntent().getExtras();
float speed = bundle.getFloat("speed1");