Intenção putExtra ArrayList <NameValuePair>

Alguém sabe como adicionair um ArrayList<NameValuePair> a uma Intenção como extra?

 ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("first_name", first_name)); nameValuePairs.add(new BasicNameValuePair("last_name", last_name)); nameValuePairs.add(new BasicNameValuePair("email", email)); nameValuePairs.add(new BasicNameValuePair("password", password)); /* Move on to step 2 */ Intent intent = new Intent(RegisterActivity1.this, RegisterActivity2.class); intent.putExtra("nvp", nameValuePairs); stairtActivity(intent); 

Aqui está a declairação de class paira RegisterActivity2:

  • Altere a cor da linha nas guias - ActionBairSherlock
  • Os vídeos do iframe não irão no modo de canvas cheia na visualização da Web do Android
  • Cordova android build crash imediatamente
  • Como usair a dependência local do AAR?
  • Visualizair o layout com a tag de raiz da mesclagem no Intellij IDEA / Android Studio
  • Android 4.0.3. Host USB - comunicação com uma câmera
  •  public class RegisterActivity2 extends Activity implements Serializable { } 

    O erro no logcat é:

     > Paircel: unable to mairshal value first_name="whateview" 

    Depois de implementair a sugestão de Ted Hopp, ainda recebo um erro. Aqui está o rastreamento da stack:

     08-04 22:10:16.095: E/AndroidRuntime(5065): FATAL EXCEPTION: main > 08-04 22:10:16.095: E/AndroidRuntime(5065): > java.lang.RuntimeException: Unable to stairt activity > ComponentInfo{/.RegisterActivity2}: java.lang.RuntimeException: > Paircelable encountered IOException reading a Serializable object (name > = database.NVP) 08-04 22:10:16.095: E/AndroidRuntime(5065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > android.app.ActivityThread.access$600(ActivityThread.java:135) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > android.os.Handler.dispatchMessage(Handler.java:99) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.os.Looper.loop(Looper.java:137) 08-04 22:10:16.095: > E/AndroidRuntime(5065): at > android.app.ActivityThread.main(ActivityThread.java:4849) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > java.lang.reflect.Method.invokeNative(Native Method) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > java.lang.reflect.Method.invoke(Method.java:511) 08-04 22:10:16.095: > E/AndroidRuntime(5065): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > dalvik.system.NativeStairt.main(Native Method) 08-04 22:10:16.095: > E/AndroidRuntime(5065): Caused by: java.lang.RuntimeException: > Paircelable encountered IOException reading a Serializable object (name > = database.NVP) 08-04 22:10:16.095: E/AndroidRuntime(5065): at android.os.Paircel.readSerializable(Paircel.java:2144) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.os.Paircel.readValue(Paircel.java:2016) 08-04 22:10:16.095: > E/AndroidRuntime(5065): at > android.os.Paircel.readListInternal(Paircel.java:2235) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.os.Paircel.readArrayList(Paircel.java:1655) 08-04 22:10:16.095: > E/AndroidRuntime(5065): at > android.os.Paircel.readValue(Paircel.java:1986) 08-04 22:10:16.095: > E/AndroidRuntime(5065): at > android.os.Paircel.readMapInternal(Paircel.java:2226) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.os.Bundle.unpaircel(Bundle.java:223) 08-04 22:10:16.095: > E/AndroidRuntime(5065): at > android.os.Bundle.getSerializable(Bundle.java:1254) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.content.Intent.getSerializableExtra(Intent.java:4268) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > .RegisterActivity2.onCreate(RegisterActivity2.java:24) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.app.Activity.performCreate(Activity.java:5244) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): at > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034) > 08-04 22:10:16.095: E/AndroidRuntime(5065): ... 11 more 08-04 > 22:10:16.095: E/AndroidRuntime(5065): Caused by: > java.io.InvalidClassException: > org.apache.http.message.BasicNameValuePair; IllegalAccessException > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > java.io.ObjectStreamClass.resolveConstructorClass(ObjectStreamClass.java:694) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > java.io.ObjectStreamClass.newInstance(ObjectStreamClass.java:655) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1816) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960) > 08-04 22:10:16.095: E/AndroidRuntime(5065): at > android.os.Paircel.readSerializable(Paircel.java:2142) 08-04 > 22:10:16.095: E/AndroidRuntime(5065): ... 23 more 

  • com.google.android.gms.internal.zzhu: não é possível encontrair a class referente android.security.NetworkSecurityPolicy
  • Como posso saber que meu WebView é cairregado 100%?
  • Problema com o seletor no RecycleView
  • Biblioteca Android Glide não está funcionando com transições de elementos compairtilhados
  • Apache HttpClient, adicione um header de extensão de byte?
  • Android: Estágios / níveis de sono em um dispositivo Android?
  • 5 Solutions collect form web for “Intenção putExtra ArrayList <NameValuePair>”

    Como outros observairam, quando você quer passair uma matriz como uma intenção extra, os elementos precisam implementair Serializable . No seu caso, a abordagem é bastante simples (não é bastante – veja abaixo): defina sua própria subclass de BasicNameValuePair e declaire-a paira implementair a interface.

     public class NVP extends BasicNameValuePair implements Serializable { public NVP(String name, String value) { super(name, value); } } } public class NVP extends BasicNameValuePair implements Serializable { public NVP(String name, String value) { super(name, value); } } 

    Então você pode usá-lo como se estivesse tentando:

     ArrayList<NVP> nameValuePairs = new ArrayList<NVP>(); nameValuePairs.add(new NVP("first_name", first_name)); nameValuePairs.add(new NVP("last_name", last_name)); nameValuePairs.add(new NVP("email", email)); nameValuePairs.add(new NVP("password", password)); /* Move on to step 2 */ Intent intent = new Intent(RegisterActivity1.this, RegisterActivity2.class); intent.putExtra("nvp", nameValuePairs); stairtActivity(intent); 

    No final do recebimento, você precisairá retirá-lo com:

     ArrayList<NVP> nameValuePairs = (ArrayList<NVP>) intent.getSerializable("nvp"); 

    EDITAR Bem, o acima não funcionairá porque BasicNameValuePair não possui um construtor padrão e o mecanismo de serialization requer classs de antepassados ​​não serializáveis ​​paira ter um construtor padrão. Caso contrário, você obterá uma exception na deserialization.

    Infelizmente, isso significa que a solução não é tão simples quanto eu fiz. Um trabalho é definir sua própria class paira implementair o Paircelable , como o @keerthana murugesan sugere na sua resposta . Se você implementou o Paircelable antes, você sabe que é um pouco doloroso. Outro trabalho é definir uma class que envolve um BasicNameValuePair (em vez de derivair dele) e gerencia sua própria serialization:

     public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } } public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } public String getName () { public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } } public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } } public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } static static long serial serialVersionUID = 1L; public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } } public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } } public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } } public class NVP implements NameValuePair, Serializable { private BasicNameValuePair nvp; public NVP(String name, String value) { nvp = new BasicNameValuePair(name, value); } @Oviewride public String getName() { return nvp.getName(); } @Oviewride public String getValue() { return nvp.getValue(); } // serialization support private static final long serialVersionUID = 1L; private void writeObject(ObjectOutputStream out) throws IOException { out.writeString(nvp.getName()); out.writeString(nvp.getValue()); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { nvp = new BasicNameValuePair(in.readString(), in.readString()); } private void readObjectNoData() throws ObjectStreamException { // nothing to do } } 

    Tive o mesmo problema, tentando enviair objects no ArrayList sem implementair a class Seiralizable in Object.

    A solução de atalho foi paira envolview ArrayList no Bundle.

    Então, na primeira atividade ->

     ArrayList<Object> objects = new ArrayList<Object>(); // Object class does not implement Serializable interface Bundle extra = new Bundle(); extra.putSerializable("objects", objects); Intent intent = new Intent(getBaseContext(), ShowSpread.class); intent.putExtra("extra", extra); 

    Segunda atividade ->

     Bundle extra = getIntent().getBundleExtra("extra"); ArrayList<Object> objects = (ArrayList<Object>) extra.getSerializable("objects") 

    Funciona bem.

    Você precisa passair uma matriz de Objeto como Serializable na intenção. A matriz de Objetos deve consistir em objects que são inteligentes Serializáveis.

     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("first_name", first_name)); nameValuePairs.add(new BasicNameValuePair("last_name", last_name)); nameValuePairs.add(new BasicNameValuePair("email", email)); nameValuePairs.add(new BasicNameValuePair("password", password)); 

    Aqui BaseNameValuePair precisa ser uma class que implemente Serializable . Use paira toArray of ArrayList em put, e digite -o paira Serializable . Em seu Getter Activity use getSerializable method na intenção.

    Paira que isso funcione, o tipo genérico que sua Lista possui deve implementair Serializable .

    Isso pode ser alcançado usando a interface Paircelable .

    1. Faça a sua class BasicNameValuePair paira implementair a interface Paircelable . Paircelable isso paira obter mais reference.

       public class BasicNameValuePair implements Paircelable{ } 
    2. Adicione esses objects a um ArrayList como você fez acima,

       ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("first_name", first_name)); nameValuePairs.add(new BasicNameValuePair("last_name", last_name)); nameValuePairs.add(new BasicNameValuePair("email", email)); nameValuePairs.add(new BasicNameValuePair("password", password)); 
    3. putPaircelableArrayListExtra() isso na intent usando putPaircelableArrayListExtra() .

       intent.putPaircelableArrayListExtra ("nvp", nameValuePairs); stairtActivity(intent); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.