Still need to restore Activities when rotating the phone?

Asked

Viewed 101 times

1

A little while ago, every time an Android app was developed, you had to worry about the data that was on the screen when you rotated your phone (change the orientation). As explained in that post it was necessary to recreate the Activity.

Recently, when programming, I have noticed that when turning the cell phone (both in AVD and real cell) the data is no longer destroyed. Can anyone tell if anything has changed? No need to manually restore Activity?

1 answer

0


It’s still necessary, yes. What happens is that many components already do this restore for you automatically, so you don’t notice. A text field can, for example, save what was written on it and restore when the screen is recreated. Many components have a satisfactory implementation. However, when the state is complex and depends on the logic of its application, there is no miracle.

Moreover, something that is possible now and was not before is the use of setRetainInstance(true) us Fragments, so that they are not destroyed during a configuration change (in our case, screen rotation). However, this does not solve the problem of loss of status in the case of your Fragment be destroyed by the system to recover memory, so the best thing to do is, yes, save and restore the state yourself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.