[android-developers] Re: Pass ArrayList parameters between two activities.
There's no simple way. You are on the right track. 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 Thanks and Regards, Kumar Bibek On Apr 19, 11:46 am, Ke Wu wrote: > -- Forwarded message -- > From: Ke Wu > Date: 2010/4/19 > Subject: Pass ArrayList parameters between two activities. > To: android-developers@googlegroups.com > > Hi all, > Today I met a problem, I need to pass a ArrayList from an > activity to another. I dont know what the Intent exactly do when I use > putExtra to pass in an ArrayList object. > > I guess MyClass need to implement Parcelable interface, so I just did > it. But still, it does not work. > > Maybe I need to create a Bundle and then use Bundle's > putParcelableArrayList > method to put my ArrayList object in, and then pass this bundle as > parameter of putExtra to the intent. > So crazy! I am lazy, I just want to pass an ArrayList object > simply, is there a simple way?? > > Any suggestion would be greatly appreciated! > > kerl.d.w > > -- > 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 > 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 For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Pass ArrayList parameters between two activities.
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 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" wrote: > On Mon, Apr 19, 2010 at 1:24 AM, Ke Wu wrote: > > I dont know what the Intent exactly do when I use putExtra to pass in an > > ArrayList object. > > Did you read the documentation on Intents? Specifically > this:http://developer.android.com/intl/fr/reference/android/content/Intent..., > java.util.ArrayList) > > > 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 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 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 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 > 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@goo
[android-developers] Re: Pass ArrayList parameters between two activities.
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 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 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" wrote: > > > > > > > On Mon, Apr 19, 2010 at 1:24 AM, Ke Wu wrote: > > > I dont know what the Intent exactly do when I use putExtra to pass in an > > > ArrayList object. > > > Did you read the documentation on Intents? Specifically > > this:http://developer.android.com/intl/fr/reference/android/content/Intent..., > > java.util.ArrayList) > > > > 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 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 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 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 t
Re: [android-developers] Re: Pass ArrayList parameters between two activities.
Thanks, I got it. 2010/4/19 Kumar Bibek > There's no simple way. You are on the right track. > > 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 > > Thanks and Regards, > Kumar Bibek > > On Apr 19, 11:46 am, Ke Wu wrote: > > -- Forwarded message -- > > From: Ke Wu > > Date: 2010/4/19 > > Subject: Pass ArrayList parameters between two activities. > > To: android-developers@googlegroups.com > > > > Hi all, > > Today I met a problem, I need to pass a ArrayList from an > > activity to another. I dont know what the Intent exactly do when I use > > putExtra to pass in an ArrayList object. > > > > I guess MyClass need to implement Parcelable interface, so I just > did > > it. But still, it does not work. > > > > Maybe I need to create a Bundle and then use Bundle's > > putParcelableArrayList > > method to put my ArrayList object in, and then pass this bundle > as > > parameter of putExtra to the intent. > > So crazy! I am lazy, I just want to pass an ArrayList object > > simply, is there a simple way?? > > > > Any suggestion would be greatly appreciated! > > > > kerl.d.w > > > > -- > > 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 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 > 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
Re: [android-developers] Re: Pass ArrayList parameters between two activities.
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 > 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 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 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" wrote: > > > > > > > > > > > > > On Mon, Apr 19, 2010 at 1:24 AM, Ke Wu wrote: > > > > I dont know what the Intent exactly do when I use putExtra to pass in > an > > > > ArrayList object. > > > > > Did you read the documentation on Intents? Specifically this: > http://developer.android.com/intl/fr/reference/android/content/Intent..., > > > java.util.ArrayList) > > > > > > 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 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 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 > 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
Re: [android-developers] Re: Pass ArrayList parameters between two activities.
On Tue, Apr 20, 2010 at 12:31 AM, Arpit wrote: > Now I call Activity B and passing new Intent where I have put > extra (Parcelable object) > How are you adding the parcelables? I don't see that in what you posted. - TreKing - Chicago transit tracking app for Android-powered devices http://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 For more options, visit this group at http://groups.google.com/group/android-developers?hl=en