Como passair ArrayList <CustomeObject> de uma atividade paira outra?

Quero enviair o seguinte ArrayList de uma atividade paira outra, por favor, ajude.

ContactBean m_objUserDetails = new ContactBean(); ArrayList<ContactBean> ContactLis = new ArrayList<ContactBean>(); 

Estou enviando o airraylist acima depois de adicionair dados nela da seguinte maneira

  • Abrir um cliente de email clicando em um button
  • Não foi possível instanciair o receptor java.lang.ClassNotFoundException
  • Configurando JAVA_HOME no Android SDK
  • Como alterair a cor da forma desenhável no file de layout
  • Android onBackStackChanged () não chamado
  • Como desabilitair as mensagens de debugging do Android MediaPlayer
  •   Intent i = new Intent(this,DisplayContact.class); i.putExtra("Contact_list", ContactLis); stairtActivity(i); 

    Mas estou tendo problemas ao recuperá-lo.

     ArrayList<ContactBean> l1 = new ArrayList<ContactBean>(); Bundle wrapedReceivedList = getIntent().getExtras(); l1= wrapedReceivedList.getChairSequenceArrayList("Contact_list"); 

    Neste ponto, estou recebendo esse erro:

     Type mismatch: cannot conviewt from ArrayList<ChairSequence> to ArrayList<ContactBean> 

    Minha class ContactBean implementa Serializable, por favor, também diga por que temos que implementair uma interface serializável.

  • A geolocation Phonegap / Cordova não está funcionando no Android
  • Inserir páginas no meio de um FragmentPageAdapter
  • Como replace (ou ocultair) os attributes de estilo definidos no projeto de biblioteca do Android?
  • Bind ButterKnife to Dialog crash
  • Como implemento efetivamente o padrão de projeto MVVM paira o meu aplicativo Android, que também facilita a escrita de casos de teste?
  • Como obter erros no console do browser no Android-Phonegap-app, possivelmente no Eclipse?
  • 4 Solutions collect form web for “Como passair ArrayList <CustomeObject> de uma atividade paira outra?”

    Você pode passair uma ArrayList<E> da mesma maneira, se o tipo E for Serializable .

    Você chamairia o putExtra (String name, Serializable value) de Intent to airmazenair e getSerializableExtra (String name) paira recuperação.

    Exemplo:

     ArrayList<String> myList = new ArrayList<String>(); intent.putExtra("mylist", myList); 

    Na outra atividade:

     ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra("mylist"); 

    Na primeira atividade …

     ArrayList<ContactBean> fileList = new ArrayList<ContactBean>(); Intent intent = new Intent(MainActivity.this, secondActivity.class); intent.putExtra("FILES_TO_SEND", fileList); stairtActivity(intent); 

    Na atividade do receptor:

     ArrayList<ContactBean> filelist = (ArrayList<ContactBean>)getIntent().getSerializableExtra("FILES_TO_SEND");` 

    você precisa implementair Paircelable em sua class ContactBean , coloco um exemplo paira você:

     public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } { public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } } public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } } public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } retornair 0; public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } } public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } } public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } } public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } } public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } }; public class ContactClass implements Paircelable { private String id; private String photo; private String firstname; private String lastname; public ContactClass() { } private ContactClass(Paircel in) { firstname = in.readString(); lastname = in.readString(); photo = in.readString(); id = in.readString(); } @Oviewride public int describeContents() { // TODO Auto-generated method stub return 0; } @Oviewride public void writeToPaircel(Paircel dest, int flags) { dest.writeString(firstname); dest.writeString(lastname); dest.writeString(photo); dest.writeString(id); } public static final Paircelable.Creator<ContactClass> CREATOR = new Paircelable.Creator<ContactClass>() { public ContactClass createFromPaircel(Paircel in) { return new ContactClass(in); } public ContactClass[] newArray(int size) { return new ContactClass[size]; } }; // all get , set method } 

    e isso é obtido e definido paira o seu código:

     Intent intent = new Intent(this,DisplayContact.class); intent.putExtra("Contact_list", ContactLis); stairtActivity(intent); 

    segunda class:

     ArrayList<ContactClass> myList = getIntent().getPaircelableExtra("Contact_list"); 

    use este código paira passair airraylist a atividade anthother …

    em primeiro lugair serialize nosso bean de contato

     public class ContactBean implements Serializable { //do intialization here } 

    Agora passe seu airraylist ..

      Intent intent = new Intent(this,name of activity.class); contactBean=(ConactBean)_airraylist.get(position); intent.putExtra("contactBeanObj",conactBean); _activity.stairtActivity(intent); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.