Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

rotation - How to avoid restarting activity when orientation changes on Android

I am creating an Android app in which I'm drawing a view on a canvas. When the device's orientation changes, the activity restarts. I don't want it to.

How can I avoid restarting the activity when the orientation changes?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are various ways to do it, but as given here, using

android:configChanges="keyboardHidden|orientation|screenSize"

allows you to listen for the config changes. You then respond to these changes by overriding onConfigurationChanged and calling setContentView.

This is the way I've been doing it, but I'd be interested to know other people's thoughts.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...