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()
Save the search results. There are many ways to save, such as persisting the search results, or saving them in a static object, or passing the results back to the Activity that started it, and then passing them back when restarting Give it.
#🎜🎜#Directly use Fragment to display the search result content view. Use the 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#🎜🎜#
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
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
Pressing the exit key to exit the Activity will definitely cause the Activity to execute the
onDestroy()
method, so coming in again will definitely restartonCreate()
onDestroy()
方法的, 所以再进来肯定会重新onCreate()
想保留搜索结果我能想到2个方法
保存搜索的结果. 保存的方法比较多, 例如持久化搜索结果, 或者保存到一个静态对象里面, 或者把结果回传给启动它的Activity, 重新启动的时候再传回给它.
直接用Fragment显示搜索结果内容视图. 用Fragment点返回键时用
I can think of 2 ways to keep the search resultshide()
方法, 那么这个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 thisshow()
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#🎜🎜#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
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