Forcing Android to not redraw activity on orientat

2020-02-06 13:19发布

I have been going gaga to figure this out.
Although I have read a lot that on Orientation Change, Android kills an activity and starts it as a fresh one, and the only way to handle this is to save all the stuff inside onSaveInstanceState() and try to restore it inside onCreate().

But my activity does a lot and different kind of network activities at different times and if the orientation is changed when the network activity is being performed, I'll have to handle a lot of different and complex scenarios.

Is there any simple way to just point Android that this activity doesn't need to be redrawn at all when the orientation is changed so that it automatically saves all the data and re-uses it?

I wonder if there's any thing like that.

8条回答
手持菜刀,她持情操
2楼-- · 2020-02-06 13:53

Just answered this question earlier: Android - screen orientation reloads activity

In your case you want to completely prevent Android from killing your Activity. You'll need to update your manifest to catch the orientation change, then implement the orientation change callback to actually do whatever you need to do (which may be nothing) when an orientation change occurs.

查看更多
The star\"
3楼-- · 2020-02-06 14:00

android:screenOrientation="portrait" in the activity tag in the manifest will lock your orientation.

Check this link for more inforation.

查看更多
登录 后发表回答