Search code examples
androidandroid-activitymedia-player

android studio - moving float between activitys


Hi I've tryed some ways to move float value between activitys with intent, but it's not working for me because the value restarts.

My code:

first activity:

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

second activity:

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

The value of the float is always 0 and the application have a compilation error in the secnd line in the "second activity".

Thanks to helpers!


Solution

  • Try this:

    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");