I've made a search screen that has one tab for keywords, filters, and a search button, and three optional tabs for the different types of results (each containing a ListView
with an ArrayAdapter
). When starting the activity, the developer can optionally pass in the results as an extra Parcelable[]
if the search has already been performed. In the onCreate()
method I'm creating each of the three tabs for the Parcelable[]
passed through.
When I call a search from the button on the filter tab, I clear the tabs and recreate them with the new results, which works perfectly. The problem is that when you rotate the device, it appears that Android's automatic orientation switching support recreates the entire activity, calling onCreate()
. This means that my search results are reset to the Parcelable[]
passed through when starting the activity.
The only solution I've had so far is to call finish()
then startActivity()
to essentially restart the activity with the new results. I'm sure there must be a much simpler solution and that I've done something extremely noobish.
Is there a better way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…