Fragment Screen Rotation Response

Asked 2 years ago, Updated 2 years ago, 20 views

Hello, android beginner level developer!? It is. We are trying to keep the contents from changing even if it is fragmented.

You can change the configuration on the manifest, but I can't use it...

So, I think we can use the setRetainInstance of the fragment, but this child is not only able to regenerate the fragment, but the method other than oncreateonstory is called. Onsaved... I think we should put a conditional statement in each method

If I were to explain the current situation If you search in the fragment, display the list, and turn the screen to the side, the list will be reset, and the search box and keyboard will come out again.

I can't find anything similar. Is there any good way? How should I use the setRetainInstance? Please give me some advice.

android

2022-09-22 08:21

1 Answers

Hello.

If you simply rotate the screen, it will behave as follows.

onPause
onSaveInstanceState
onStop
onDestroyView
onDeatch
onAttach
onCreateView
onActivityCreated
onStart
onResume

It works as above, so please save the value in onSaveInstanceState and restore it again in onCreate.

In order to process the UI without simply riding on Destination, you will set the manifest's android:configchange.

It would be helpful if you refer to the following article.

Handling Orientation changes on android


2022-09-22 08:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.