How to save custom ArrayList on Android screen rotate?

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 your object and use Bundle#putParcelableArrayList() in onSaveInstanceState() and onRestoreInstanceState(). This method will store an ArrayList of Parcelables by itself. Because the subject of Parcelables (and Serializables and Bundles) sometimes makes … Read more

Is using Serializable in Android bad?

For in-memory use, Parcelable is far, far better than Serializable. I strongly recommend not using Serializable. You can’t use Parcelable for data that will be stored on disk (because it doesn’t have good guarantees about data consistency when things change), however Serializable is slow enough that I would strongly urge not using it there either. … Read more

How write Java.util.Map into parcel in a smart way?

I ended up doing it a little differently. It follows the pattern you would expect for dealing with Parcelables, so it should be familiar. public void writeToParcel(Parcel out, int flags){ out.writeInt(map.size()); for(Map.Entry<String,String> entry : map.entrySet()){ out.writeString(entry.getKey()); out.writeString(entry.getValue()); } } private MyParcelable(Parcel in){ //initialize your map before int size = in.readInt(); for(int i = 0; i … Read more

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

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); startActivity(intent); To get it from intent in another activity: Foo foo = getIntent().getExtras().getParcelable(“foo”);

how to properly implement Parcelable with an ArrayList?

You almost got it ! You just need to do : public void writeToParcel(Parcel out, int flags) { out.writeString(_mac); out.writeString(_pan); out.writeInt(_band); out.writeSerializable(_lqis); out.writeTypedList(_devices); } private ZigBeeNetwork(Parcel in) { _mac = in.readString(); _pan = in.readString(); _band = in.readInt(); _lqis = (ArrayList<Integer>) in.readSerializable(); in.readTypedList(_devices, ZigBeeDev.CREATOR); } That’s all! For your list of Integer, you can also do … Read more

Read & writing arrays of Parcelable objects

You need to write the array using the Parcel.writeTypedArray() method and read it back with the Parcel.createTypedArray() method, like so: MyClass[] mObjList; public void writeToParcel(Parcel out) { out.writeTypedArray(mObjList, 0); } private void readFromParcel(Parcel in) { mObjList = in.createTypedArray(MyClass.CREATOR); } The reason why you shouldn’t use the readParcelableArray()/writeParcelableArray() methods is that readParcelableArray() really creates a Parcelable[] … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)