From 6c8ef6075bb0eadbefb4667e84730cc31c7725c8 Mon Sep 17 00:00:00 2001 From: Andrei Buneyeu Date: Fri, 23 Sep 2016 18:49:16 +0100 Subject: [PATCH 1/2] Crash fix on Save/Restore state: http://stackoverflow.com/a/14866690/554281 --- .../src/main/java/mabbas007/tagsedittext/TagsEditText.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java b/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java index 5f8fb01..521df9a 100644 --- a/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java +++ b/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java @@ -274,9 +274,10 @@ public void onRestoreInstanceState(Parcelable state) { mIsSpacesAllowedInTags = bundle.getBoolean(ALLOW_SPACES_IN_TAGS, mIsSpacesAllowedInTags); mLastString = bundle.getString(LAST_STRING); - Tag[] tags = (Tag[]) bundle.getParcelableArray(TAGS); - - if (tags != null) { + Parcelable[] tagsParcelables = bundle.getParcelableArray(TAGS); + if (tagsParcelables != null) { + Tag[] tags = new Tag[tagsParcelables.length]; + System.arraycopy(tagsParcelables, 0, tags, 0, tagsParcelables.length); Collections.addAll(mTags, tags); buildStringWithTags(mTags); mTextWatcher.afterTextChanged(getText()); From 408a6297e02dd09b9dc399bd3cc7daece51405b6 Mon Sep 17 00:00:00 2001 From: Andrei Buneyeu Date: Mon, 26 Sep 2016 17:27:28 +0100 Subject: [PATCH 2/2] Reset tags on Save/Restore state to avoid double adding --- .../src/main/java/mabbas007/tagsedittext/TagsEditText.java | 1 + 1 file changed, 1 insertion(+) diff --git a/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java b/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java index 521df9a..afaa4dd 100644 --- a/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java +++ b/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java @@ -278,6 +278,7 @@ public void onRestoreInstanceState(Parcelable state) { if (tagsParcelables != null) { Tag[] tags = new Tag[tagsParcelables.length]; System.arraycopy(tagsParcelables, 0, tags, 0, tagsParcelables.length); + mTags = new ArrayList<>(); Collections.addAll(mTags, tags); buildStringWithTags(mTags); mTextWatcher.afterTextChanged(getText());