Android Question Activity destroy on rotation

RjCl

Member
Licensed User
Longtime User
Hello,

Is it possible to keep state of some views like WebView intact if screen is rotated? I know about how Android destroys the activity and re-creates but i notice on Viber rotating the screen it does not, all is kept as is while changing orientation?
 

derez

Expert
Licensed User
Longtime User
You have two options but neither is doing what you ask:
1. Do not let the screen rotate by #SupportedOrientations
2. Store all the variables and views properties (in keystore or other ways) during activity_pause and fill the data again from the storage in activity_resume.
 
Upvote 0

RjCl

Member
Licensed User
Longtime User
Thanks derez,

Good options, but wondering how on something like Viber it is done ? If anyone is using Viber, can check that in the chat window, even with loading over 100 previous messages, after rotating the screen the webview stays as it is, even the scrollbar doesnt move and no screen flicker and no refresh?
 
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
Don't know how Viber does things. I can think of a few possibilities. One would be that every aspect of the view is saved, including scroll bar position, and recreated exactly after rotation, done in a very efficient manner so no flickering is noticed. It would also be possible that the app runs only in portrait on the OS and handles rotation itself within the app. That would be a more complicated way, you would need to swap x and y when drawing, and everything would need to be rotated 90°. I would suspect that the former method is what is being used.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…