parcelable

Android: How to pass Parcelable object to intent and use getParcelable method of bundle?

社会主义新天地 提交于 2019-11-26 03:57:14
问题 Why bundle has getParcelableArrayList , getParcelable methods; but Intent has only putParcelableArrayListExtra method? Can I transmit only object<T> , not ArrayList of one element? Then, what is getParcelable for? 回答1: Intent provides bunch of overloading putExtra() methods. Suppose you have a class Foo implements Parcelable properly, to put it into Intent in an Activity: Intent intent = new Intent(getBaseContext(), NextActivity.class); Foo foo = new Foo(); intent.putExtra("foo ", foo);

How to pass ArrayList of Objects from one to another activity using Intent in android?

人走茶凉 提交于 2019-11-26 03:31:19
问题 I have the following in code in my onClick() method as List<Question> mQuestionsList = QuestionBank.getQuestions(); Now I have the intent after this line, as follows : Intent resultIntent = new Intent(this, ResultActivity.class); resultIntent.putParcelableArrayListExtra(\"QuestionsExtra\", (ArrayList<? extends Parcelable>) mQuestionsList); startActivity(resultIntent); I don\'t know how to pass this question lists in the intent from one activity to another activity My Question class public

Passing arraylist of objects between activities

∥☆過路亽.° 提交于 2019-11-26 03:23:56
问题 I am trying to pass an arraylist of objects between two activities, but my app crushes at the second activity. Can someone help me solve this problem... Here is my code from my first activity: Intent i = new Intent(); Bundle b = new Bundle(); b.putParcelableArrayList(\"songs\",(ArrayList<? extends Parcelable>) albumsArray.get(position).getSongs()); Log.v(\"--\", \"OK\"); i.putExtras(b); i.setClass(LatestAlbums.this, AlbumDetails.class); startActivity(i); And code from the second activity:

Android: Difference between Parcelable and Serializable?

对着背影说爱祢 提交于 2019-11-26 03:14:16
问题 Why does Android provide 2 interfaces for serializing objects? Do Serializable objects interopt with Android Binder and AIDL files? 回答1: In Android we cannot just pass objects to activities. To do this the objects must either implement Serializable or Parcelable interface. Serializable Serializable is a standard Java interface. You can just implement Serializable interface and add override methods. The problem with this approach is that reflection is used and it is a slow process. This method

Help with passing ArrayList and parcelable Activity

馋奶兔 提交于 2019-11-26 02:55:10
问题 So I\'ve been googling most of yesterday and last nite and just can\'t seem to wrap my head around how to pass an arraylist to a subactivity. There are tons of examples and snippets passing primitive data types, but what I have is an arraylist of type address (address.java below). I\'ve found a lot of stuff on stackoverflow and around the web on this, but nothing that got a lot of attention except for one with a GeoPoint example. Again, it looked to me like they just flattened the GeoPoint

How to marshall and unmarshall a Parcelable to a byte array with help of Parcel?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 02:53:06
问题 I want to marshall and unmarshall a Class that implements Parcelable to/from a byte array. I am well aware of the fact that the Parcelable representation is not stable and therefore not meant for long term storage of instances. But I have a use case where I need to serialize a object and it\'s not a showstopper if the unmarshalling fails because of an internal Android change. Also the class is already implementing the Parcelable interface. Given an class MyClass implements Parcelable , how

How to save custom ArrayList on Android screen rotate?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 02:52:00
问题 I have an ArrayList with custom objects that I would like to be able to save and restore on a screen rotate. I know that this can be done with onSaveInstanceState and onRestoreInstanceState if I were to make the ArrayList its own class, which implements either Parcelable or Serializable ... But is there a way to do this without creating another class? 回答1: You do not need to create a new class to pass an ArrayList of your custom objects. You should simply implement the Parcelable class for

Benefit of using Parcelable instead of serializing object

走远了吗. 提交于 2019-11-26 01:37:27
问题 As I understand, Bundle and Parcelable belongs to the way Android performs serialization in. It is used for example in passing data between activities. But I wonder, if there are any benefits in using Parcelable instead of classic serialization in case of saving state of my business objects to the internal memory for example? Will it be simpler or faster than the classic way? Where should I use classic serialization and where better to use bundles? 回答1: From "Pro Android 2" NOTE: Seeing

How can I make my custom objects Parcelable?

我的梦境 提交于 2019-11-26 01:18:48
问题 I\'m trying to make my objects Parcelable. However, I have custom objects and those objects have ArrayList attributes of other custom objects I have made. What would be the best way to do this? 回答1: You can find some examples of this here, here (code is taken here), and here. You can create a POJO class for this, but you need to add some extra code to make it Parcelable . Have a look at the implementation. public class Student implements Parcelable{ private String id; private String name;

How can I pass a Bitmap object from one activity to another

冷暖自知 提交于 2019-11-25 23:00:56
问题 In my activity, I create a Bitmap object and then I need to launch another Activity , How can I pass this Bitmap object from the sub-activity (the one which is going to be launched)? 回答1: Bitmap implements Parcelable , so you could always pass it with the intent: Intent intent = new Intent(this, NewActivity.class); intent.putExtra("BitmapImage", bitmap); and retrieve it on the other end: Intent intent = getIntent(); Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage"); 回答2: