Reputation: 3876
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
Upvotes: 0
Views: 2298
Reputation: 30088
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.
Upvotes: 1