There are two things you must pay attention to: 1. Your class must implements Parcelable with it's CREATOR. 2. In the receiver activity, you should use getParcelable method to get your Parcelable object from the Extras bundle.
2010/4/20 Arpit <robin.ca...@gmail.com> > This works if I change the class Services from being Parceable to > Serializable it works... I am not sure why... but between Activity > when I am sending Serialized data it works but not if I send parceable > data. > > Regards, > Arpit > > On Apr 20, 10:31 am, Arpit <robin.ca...@gmail.com> wrote: > > Similar problem but this doesn't work. Following steps exists in my > > apps and still not able to send data part of Intent (putExtras) from > > one activity to another: > > > > - Activity A is of type ListActivity showing some buttons. > > - Any button click shows a Login screen (AlertDialog). > > - onCreateDialog is implemented and I have two buttons on the > > AlertDialog, Ok & Cancel, both having listener for onClick event. I > > realize that if I try to start activity within onClick event of OK > > BUTTON, the activity wont start. > > - So I implemented onDismissListener and started activity from here. > > - Now I call Activity B and passing new Intent where I have put extra > > (Parcelable object) > > > > In activity B the parcelable object comes empty... No info in it. > > > > Code below: > > > > Activity A (HomeActivity) > > > > @Override > > public void onDismiss(DialogInterface > dialog) { > > try{ > > HomeActivity home = > (HomeActivity) > > ((AlertDialog)dialog).getOwnerActivity(); > > Intent oldIntent = > home.getIntent(); > > oldIntent.setClass(home, > ServiceListActivity.class); > > > home.startActivityForResult(oldIntent,0); > > }catch(Exception e){ > > > Toast.makeText(HomeActivity.this, R.string.error_occured, > > Toast.LENGTH_LONG).show(); > > } > > } > > > > Activity B (ServiceListActivity) > > > > public void onCreate(Bundle savedInstanceState){ > > try{ > > super.onCreate(savedInstanceState); > > setContentView(R.layout.middle_man); > > Intent i = super.getIntent(); > > Bundle b = i.getExtras(); > > Iterator<String> iterator = > b.keySet().iterator(); > > Services a = null; > > while(iterator.hasNext()){ > > a = > (Services)b.getParcelable(iterator.next()); > > } > > Services s = > (Services)b.get(ServicesConstants.SERVICE_SELECTED); > > ... > > ... > > > > Both 'a' and 's' comes null. They are type object "Services" which is > > Parceable in nature. > > > > Regards, > > Arpit > > > > On Apr 20, 1:50 am, "~ TreKing" <treking...@gmail.com> wrote: > > > > > > > > > > > > > On Mon, Apr 19, 2010 at 1:24 AM, Ke Wu <kerl....@gmail.com> wrote: > > > > I dont know what the Intent exactly do when I use putExtra to pass in > an > > > > ArrayList<MyClass> object. > > > > > Did you read the documentation on Intents? Specifically this: > http://developer.android.com/intl/fr/reference/android/content/Intent..., > > > java.util.ArrayList<? extends android.os.Parcelable>) > > > > > > I guess MyClass need to implement Parcelable interface, so I just did > it. > > > > But still, it does not work. > > > > > You guess right. If it does not work, you should explain what doesn't > work. > > > Just saying "it does not work" is useless to someone trying to help > you. > > > > > > Maybe I need to create a Bundle and then use Bundle' > putParcelableArrayList > > > > method to put my ArrayList<MyClass> object in, and then pass this > bundle as > > > > parameter of putExtra to the intent. > > > > > No. > > > > > > So crazy! > > > > > Not really! > > > > > > I am lazy > > > > > Then you should not being doing Android development ... or any kind of > > > programming for that matter. > > > > > > , I just want to pass an ArrayList<MyClass> object simply, is there a > > > > simple way?? > > > > > > Any suggestion would be greatly appreciated! > > > > > See the link I posted. > > > > > On Mon, Apr 19, 2010 at 3:23 AM, Kumar Bibek <coomar....@gmail.com> > wrote: > > > > However, a cheap workaround would be to have this arraylist as a > static > > > > variable of your source activity. This way, you can access this Array > List > > > > from your destination activity > > > > > Except that by doing this, you have to make sure the list is actually > valid. > > > If you start Activity A, fill the list, start Activity B, press Home, > wait a > > > while, come back to your app, your app may have been killed since you > > > started it, the list will be empty, but you will be back in Activity B. > If > > > you don't validate that list and save and restore it somehow, you will > run > > > into trouble trying to access the empty (or null) list. > > > > > > ------------------------------------------------------------------------------------------------- > > > TreKing - Chicago transit tracking app for Android-powered > deviceshttp://sites.google.com/site/rezmobileapps/treking > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Developers" group. > > > To post to this group, send email to > android-developers@googlegroups.com > > > To unsubscribe from this group, send email to > > > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > > > For more options, visit this group athttp:// > groups.google.com/group/android-developers?hl=en > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > > For more options, visit this group athttp:// > groups.google.com/group/android-developers?hl=en- Hide quoted text - > > > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en