Activity still being destroyed when keyboard is shown even though I've configured the activity to handle that configuration change

ساخت وبلاگ

Vote count: 0

I don't want my activity to be destroyed when the keyboard pops up or goes away, so I added the appropriate xml attributes in the android manifest; namely, android:configChanges="keyboard|keyboardHidden. In the android documentation it says:

you can declare that your activity handles the configuration change itself, which prevents the system from restarting your activity....To declare that your activity handles a configuration change, edit the appropriate element in your manifest file to include the android:configChanges attribute with a value that represents the configuration you want to handle.

However, it seems like the state of the views in the activity are still being saved and then restored when the keyboard is shown. Here is why:

In this particular fragment, when the keyboard pops up it means the user is about to make a search. When that search is executed new Item objects are received, any old Item objects in the fragment's recyclerview's adapter are deleted, the new ones are added, and notifyDataSetChanged() is called -- which should trigger the viewholders to show the new items.

What happens instead is that the results are received, the results from any previous searches are removed from the adapter, the new results are added, but something funny happens with the viewholders. Sometimes they won't even change, and sometimes they change for like a split-second, but then revert back to whatever they were showing before that split-second change.

I know, by default, android saves the state of the views in an activity's view hierarchy whenever the activity is destroyed as a result of a configuration change, and then restores that saved state in onRestoreInstanceState(). That's what seems like is happening here:

The viewholders reflect particular items before the keyboard pops up, when the keyboard pops up the state of the viewholders are saved, then when the user finishes typing in the search and executes it, the items are received, the old items are deleted, the new items are added, the keyboard is hidden, and the viewholders change for a split-second, but then onRestoreInstanceState() is called reverting the viewholders back to what they were showing before the keyboard popped up.

If the state is being restored when the keyboard goes down, why is that when I set the android:configChanges="keyboard|keyboardHidden attribute in my manifest for the corresponding activity.

asked 39 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 244 تاريخ : چهارشنبه 10 شهريور 1395 ساعت: 23:53