Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to retrieve a Double value from one activity to another?

I have made an application containing 2 activities ,in that first activity contains some EditTexts (decimal numbers),and anothe ractivity also contains some Edtitexts(decimal) ,now I want to pass one EditText's value to another but as a "double" not as a string.Because that values will be used in mathematical calculation. I want that values in "double" strictly. I have tried as below: but have no idea how to cast a String to "double".

activity1.java

    final Double d1;
        final Double d2;
        final Double d3;
        final Double d4;
        final Double d5;
        final Double d6;
        final Double d7;
        final Double d8;
        d1=Double.parseDouble(et1.getText().toString());
        d2=Double.parseDouble(et2.getText().toString());
        d3=Double.parseDouble(et3.getText().toString());
        d4=Double.parseDouble(et4.getText().toString());
        d5=Double.parseDouble(et5.getText().toString());
        d6=Double.parseDouble(et6.getText().toString());
        d7=Double.parseDouble(et7.getText().toString());
        d8=Double.parseDouble(et8.getText().toString());
.
.
.
.
Intent ic = new Intent(Calculator_1Activity.this,Calculator2a.class);
        ic.putExtra("doubleValue_e1", d1);
        ic.putExtra("doubleValue_e2", d2);
        ic.putExtra("doubleValue_e3", d3);
        ic.putExtra("doubleValue_e4", d4);
        ic.putExtra("doubleValue_e5", d5);
        ic.putExtra("doubleValue_e6", d6);
        ic.putExtra("doubleValue_e7", d7);
        ic.putExtra("doubleValue_e8", d8);

        startActivity(ic);

Activity2.java

Intent receiveIntent = this.getIntent();
        e1 = receiveIntent.getDoubleExtra("doubleValue_e1", 0.00);
        e2 = receiveIntent.getDoubleExtra("doubleValue_e2", 0.00);
        e3 = receiveIntent.getDoubleExtra("doubleValue_e3", 0.00);
        e4 = receiveIntent.getDoubleExtra("doubleValue_e4", 0.00);
        e5 = receiveIntent.getDoubleExtra("doubleValue_e5", 0.00);
        e6 = receiveIntent.getDoubleExtra("doubleValue_e6", 0.00);
        e7 = receiveIntent.getDoubleExtra("doubleValue_e7", 0.00);
        e8 = receiveIntent.getDoubleExtra("doubleValue_e8", 0.00);

        Calculator_1Activity cal1 = new Calculator_1Activity();
        et1.setText(cal1.et1.getText().toString());

i have tried this but still not working.my project stops unexpectly..

like image 804
jimmy cool Avatar asked Sep 01 '25 04:09

jimmy cool


1 Answers

Sending Double From First Activity :

Intent sendingIntent = new Intent(this,SecondActivity.class);
intent.putExtra("doubleValue_e1", doubleData);
intent.putExtra("doubleValue_e2", doubleData);
intent.putExtra("doubleValue_e3", doubleData);
intent.putExtra("doubleValue_e4", doubleData);
startActivity(sendingIntent);

Receiving Double in Second Activity :

double e1,e2,e3,e4;
Intent receiveIntent = this.getIntent();
e1 = intent.getDoubleExtra("doubleValue_e1", defaultValue)
e2 = intent.getDoubleExtra("doubleValue_e2", defaultValue)
e3 = intent.getDoubleExtra("doubleValue_e3", defaultValue)
e4 = intent.getDoubleExtra("doubleValue_e4", defaultValue)
like image 103
Miral Dhokiya Avatar answered Sep 02 '25 17:09

Miral Dhokiya