Pass object for error parameter - Android Studio

Asked

Viewed 826 times

0

I am trying to pass an object per parameter, but an error occurs on the line "it.putExtra("tag", obj);":

Cannot resolve method (java.lang.String, my.minhaClasse package)

Follow the code

Obj obj = new Obj();
Intent it;
it = new Intent(this, MinhaClasse.class);
it.putExtra("tag", obj);
startActivity(it);

Another question, how to recover this object in the other Activity?

  • Hello, this reply may help you http://answall.com/questions/70421/como-passar-informacoes-da-listview-para-uma-activity/70456#70456

  • 1

    This question may be very useful to you, Vitor: http://answall.com/questions/38492

1 answer

5


In order to pass an object as parameter it is necessary that it be Serialized, ie implement Serializable. Follow a simple example:
Class:

public class Params implements Serializable{
    public String param1="";
    public String param2="";
    public String param3="";
}

Setting the parameter:

 Params obj = new Params();
        obj.param1 = "Parametro UM ";
        obj.param2 = "Parametro DOIS ";
        obj.param3 = "Parametro TRES ";
        Intent it;
        it = new Intent(context, MainActivity.class);
        it.putExtra("Param", obj);

Greetings

Browser other questions tagged

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