I read this interesting post How to pass an object from one activity to another on Android and found that i should use putExtra to send object to other activities and to receive that using getIntent().getSerializableExtra("name") is necessary. but when i use putExtra it force me to cast the XMPPTCPConection object to (java.io.Serializable).
the java android code:
XMPPTCPConnection connection;
connection= xmppConnectio.getXMPPConnectio();
if(connection.equals(null))
Log.d("","is null");
else
Log.d("","is not null");
Intent intent= new Intent(this,chat.class);
intent.putExtra("connection", (java.io.Serializable) connection);
startActivity(intent);
but it throws exception
02-21 05:00:44.733 4672-4683/passargad.ehsan D/connected﹕ yes connected successfully :
02-21 05:00:44.733 4672-4672/passargad.ehsan D/﹕ is not null
02-21 05:00:44.733 4672-4672/passargad.ehsan D/AndroidRuntime﹕ Shutting down VM
02-21 05:00:44.733 4672-4672/passargad.ehsan W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x400205a0)
02-21 05:00:44.743 4672-4672/passargad.ehsan E/AndroidRuntime﹕ FATAL EXCEPTION: main
**java.lang.ClassCastException: org.jivesoftware.smack.tcp.XMPPTCPConnection**
at passargad.ehsan.MainActivity.triger(MainActivity.java:189)
at passargad.ehsan.XMPPConnectio$connectionXMPP.onProgressUpdate(XMPPConnectio.java:125)
at passargad.ehsan.XMPPConnectio$connectionXMPP.onProgressUpdate(XMPPConnectio.java:55)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:432) at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4277)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
the interesting part of story is that it was ok for 3 times correct executing. but then it broke.
thank you in advance!