Pergunta

I have one datepicker and one search button. On search button click, I have to pass the selected date to backend and display the fetched data in listview below search button.

In portrait mode I am able to display the data listview after clicking on search button. But when I rotate the emulator all the data getting lost.

How can I preserve the searched data to display in listview in landscape mode.

Please help me. Share some example code if possible.

Foi útil?

Solução

android:configChanges="orientation|screenSize"

add this line inside your activity in manifest file. then data will not lose during orientation change

Outras dicas

Look into using onSaveInstanceState and onRestoreInstanceState. Or you could save the data you need into SharedPreferences, however, personally I'd use the InstanceState methods

You could lock the activity in one orientation by adding android:screenOrientation="portrait" (or "landscape") to in your manifest.

you could distinguish the cases of your activity being created for the first time and being restored from savedInstanceState. This is done by overriding onSaveInstanceState and checking the parameter of onCreate.

android:configChanges="screenOrientation" in the tag. This way the activity will not be recreated, but will receive a callback instead (which you can ignore as it's not useful for you).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top