Search code examples
androidandroid-intentparcelable

can i get several intents in the same class using getparcelableextra


could someone please answer my question. in my activity class.java, I have an intent and i want to send an object using intent. when I searched for it, the results were I have to implement parcelable to the class "object" that I want to send it. I did that but the thing is I want to put two objects to be sent to main2activity.java, when I tried to do that, my app crashed, when I debugged it said that main2activity has much intent? so my question is how can I send two objects using put extra, and get them in the other java using getintent.getparcelableextra()?

mainactivity.java

clickedplace is an object of class called Place

Intent myintent = new Intent(getApplicationContext(), localpopup.class);
                    myintent.putExtra("localprice",clickedplace.getTicketId().getLocalPrice());
                    myintent.putExtra("placeobject", clickedplace.getId());

main2activity.java localpriceplace of type double getpressplace of type Place

localpriceplace= getIntent().getParcelableExtra("localprice");
        getpressedplace= (Place) getIntent().getParcelableExtra("placeobject");

Solution

  • You should be able to do this by creating a Bundle and putting each Intent into it with a String key. In "main2activity" you should retrieve them by name.

    But the bundle into a new Intent and send that to main2activity

    Otherwise, if you are putting data into each Intent and then sending the Intent directly to main2activity, you will need to implement "onNewIntent" in main2activity to get the new data.