0

I'm new to android app development and I'm trying to send the SoapObject which is in MainActivity to the 2nd Activity using intents, by trying to put the soapObject in a Bundle. I'm getting an error:

unable to cast SoapObject to Bundle

Is there any possible way to send the SoapObject to the 2nd Activity?

CharliePrynn
  • 3,034
  • 5
  • 40
  • 68
Pavan Teja
  • 41
  • 11
  • How are you adding your SoapObjec to the intent? Please, post your code – mromer Apr 29 '15 at 11:56
  • @mromer: this is the code in MainActivity : ' try { response = (SoapObject) soapPackage.getResponse(); } } catch (SoapFault e) { e.printStackTrace(); } Bundle bundle = new Bundle(); bundle.putBundle("response",(Bundle) response); intent.putExtras(bundle); ' – Pavan Teja Apr 29 '15 at 16:28
  • @mromer : this is the code in 2nd activity where i should get the soapobject : " Bundle bundle = getIntent().getExtras(); Bundle bundle1 = bundle.getBundle("response"); System.out.println("response : " + bundle1.toString()); " – Pavan Teja Apr 29 '15 at 16:33

1 Answers1

1

You can't cast SoapObject to Bundle becouse it do not inherits from Bundle. As far as i know You cant send it like that becouse SoapObject dont implements Parcelable interface.

Here is a discussion about the problem: How to pass an object from one activity to another on Android and You may try to use solution with static class members (https://stackoverflow.com/a/7454611/4114960) but myself i think it's NOT very good idea. You may experience problems coused by overlooking sth related to Activities lifecycles.

Why don't You parse answer from SoapObject to String, or List etc. and pass it safe with putString, putStringArrayList etc.?

Community
  • 1
  • 1
mmprog
  • 771
  • 10
  • 21
  • Hi, the answers you linked to are making the custom classes implement `Serializable`. `SoapObject` does not implement `Serializable`, [but implements `KvmSerializable`](http://kobjects.org/ksoap2/doc/api/org/ksoap2/serialization/SoapObject.html). So that method can't be used. Is that right? – Solace Aug 03 '15 at 09:29
  • You're right. Anyways for simple data it's easier to use putExtra or putStringArrayListExtra to Intent, but for complex data You best way is to define Your structure as Parcelable or Serializable and copy values from SoapObjects - it's just a bit of coding but it's allways this boring way with models in interfaces ;) – mmprog Aug 03 '15 at 16:56