我打开一个Activity列出一堆搜索结果之后按了退出键退出了,有没有办法我再打开这个Activity的时候别重新搜索,就打开刚刚退出的界面,别把onCreate重新执行一遍?
就是从这个Activity跳转到别的Activity,然后回来的效果那样
或者推出了就destroy了,没救了?
PHPz2017-04-17 17:44:27
Pressing the exit key to exit the Activity will definitely cause the Activity to execute the onDestroy()
method, so coming in again will definitely restart onCreate()
onDestroy()
方法的, 所以再进来肯定会重新onCreate()
想保留搜索结果我能想到2个方法
保存搜索的结果. 保存的方法比较多, 例如持久化搜索结果, 或者保存到一个静态对象里面, 或者把结果回传给启动它的Activity, 重新启动的时候再传回给它.
直接用Fragment显示搜索结果内容视图. 用Fragment点返回键时用hide()
方法, 那么这个Fragment的实例就不会被回收, 重新进入搜索结果页面的时候再把这个show()
hide()
method when using Fragment to click the return key, then the Fragment instance will not be recycled and the search results will be re-entered. Just put this show()
when you create the page, but this method has requirements for the jump logic of the page.#🎜🎜##🎜🎜#
#🎜🎜#
#🎜🎜#It depends on the relationship between this search results page and other pages to determine which method to use#🎜🎜#伊谢尔伦2017-04-17 17:44:27
I think you can set the launchMode of the Activity that displays the search results to singleTask, and then override the onNewIntent method of the Activity. However, the system will still kill the Activity at any time when the memory is tight. If you want to display the previous activity every time you open it, For search results, you can consider saving the search keywords in the database, and then use the last search keyword to request data every time you open it
PHP中文网2017-04-17 17:44:27
Before exiting the Activity, save the searched data into the Bundle, and then use the Bundle parameter in onCreate (which contains the data you saved before) to re-establish the View. . .
Well. . . That’s it in simple terms