smartmouse
smartmouse

Reputation: 14404

How to send 2 different values from one activity to another?

I'm editing a my friend's code in which there is this method:

private void send() {
    Intent intent = new Intent(context, MyClass.class);
    intent.putStringArrayListExtra("id", id);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
    id.removeAll(id);
}

I want to put another value (a double) to the intent. I already read other questions here on SO and tried several solutions, but nothing suit my need. How to do that?

Upvotes: 0

Views: 446

Answers (1)

SolArabehety
SolArabehety

Reputation: 8606

In the first activity, you should do:

private void send() {
    Intent intent = new Intent(context, MyClass.class);
    intent.putStringArrayListExtra("id", id);
    intent.putExtra("DobleValue", double); // HERE!
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
    id.removeAll(id);
}

And in the next activity:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle b = getIntent().getExtras();
        double dob = b.getDouble("DobleValue");
        ....
    }

Also, if you want another way to do this, you can look my answer in this post: How to keep a TextView's content when changing the Activity

Upvotes: 1

Related Questions