Problem using Putextra with a vector

Asked

Viewed 24 times

0

I cannot pass the vector inside the Putextra. Someone can help me?

Activity 1

 double[] valores = new double[vetorEdits.length];



            for (int i = 0; i < vetorEdits.length ; i++) {

                valores[i] = Double.parseDouble( vetorEdits[i].getText().toString());


            }

            Intent intent = new Intent(getApplication(),Main5Activity.class);
            intent.putExtra("valores", valores[vetorEdits.length]);
            startActivity(intent);

Activity 2

Intent intent = getIntent();

    double[] valores = getIntent().getDoubleExtra("valores", 0,0);

1 answer

2

What you’re putting in the extras is a double and not an array,

valores[vetorEdits.length]

is a double, the one that is stored in the index vetorEdits.length.

I think I might be making a mistake on that line.

You should wear it like this:

intent.putExtra("valores", valores);

To recover it you must use

double[] valores = getIntent().getDoubleArrayExtra("valores");
  • Thanks! In case, how do I use a Toast to print the past values? Gave error, the conventional way. Toast.makeText(getApplicationContext(),values,Toast.LENGTH_LONG). show();

  • What Toast presents is a String. You have to "transform" the array into one. But that’s another question. However, see here how to proceed when a reply has been useful to you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.