简体   繁体   中英

Black screen when opining landscape activity on device rotation android

Hey I have android app which is always in portrait mode
except one activity which is in landscape mode

and the way to open this activity is to rotate my device to landscape mode
and I achieve this using background service with SensorEventListener
but there are many problems I faced first one is the returned value from the SensorEvent are difference between devices

the second issue is that sometimes when I rotate my device for long period by wrong the device screen rotated for few second with black screen before loading the landscape view

I'm using the code in this library for handling orientation rotation sensor code

is the any better way to achieve this ,and what is the cause of black screen issue thanks

You don't need to use the sensors to detect device rotation - the system already does this for you.

Simply provide a different layout resource file in the res/layout-land folder. As long as you haven't done anything to force portrait-only, Android will destroy your Activity and recreate it with the new layout when the device is rotated.

The key to not having the momentary flash of 'black screen' is making sure that you don't do anything time-consuming in onCreate or onCreateView.

Make sure that you do long-running (more than a couple of hundred milliseconds) on a background thread, and never do any network access on the UI thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM