Passing a double value through another class in Android Java

I'm just wondering what are the ways to pass two or more double values ​​from class A to ClassB

the moment I found the code that this method gives me:

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

It does not miss values ​​and cannot find a way to get these values

Another question here suggested a method to create an instance of a class, but it seems that it could not pass the values ​​correctly.

I am programming for Android, so I don’t know if the method will be different.

+8
android double android-intent
source share
4 answers

You don't actually put your doubles in your Intent

 Intent yourInent = new Intent(thisActivity.this, nextActivity.class); Bundle b = new Bundle(); b.putDouble("key", doubleVal); yourIntent.putExtras(b); startActivity(yourIntent); 

Then enter it in the following action:

 Bundle b = getIntent().getExtras(); double result = b.getDouble("key"); 
+19
source share

You can try this way

 double a, b; Intent i = new Intent(classA.this, classB.class); Bundle params = new Bundle(); params.putDouble("doubleA", a); params.putDouble("doubleB", b); i.putExtras(params); startActivity(i); 

On the other hand you need something like this

 double a, b; // Get Params from intent Intent it = getIntent(); if (it != null) { Bundle params = it.getExtras(); if (params != null) { a = params.getDouble("doubleA"); b = params.getDouble("doubleB"); } } 
+2
source share

This is almost the right way to send information between actions. You need to use putDouble () method as follows:

 i.putDouble("value1", a); i.putDouble("value2", b); 

To access these values, you need to remove them from the Extras map at the end of the receiving operation like this:

 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); Intent intent=getIntent(); double a=intent.getExtras().getDouble("value1"); double b=intent.getExtras().getDouble("value2"); 
0
source share

You need to use:

 i.putExtra("number1", number1); i.putExtra("number2", number1); 
0
source share

All Articles