Handling Android screen orientation and splash screen

Sometimes, tiny little things can give the developer a big headache. I was developing a webview application to cater for both portrait and landscape layout. I created layout-land folder and create the same XML with webview there, but referencing to different splash screen image. The problem is, When I rotate, the app will restart. I tried to search thru stackoverflow for many hours, found this. Most of them suggested me to add "android:configChanges="orientation|screenSize"" in AndroidManifest like below.

            < android:name=".MyActivity"
            android:label="@string/title_activity_myactivity"
            android:configChanges="orientation|screenSize" android:screenOrientation="unspecified" >
But, my application target was 2.2 and it doesn't allow me to add "orientation" in "android:configChanges". Later, I changed the application to target 4.0, only then it works. The app won't restart anymore when the orientation changes. And overwrite the following method in the Activity.

//must override this, if not, screen orientation will make the app force close
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);
    }
Some other things i learnt from my previous project:

1. To remove the title bar from the app (AndroidManifest.xml)

        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
2. the great splash screen example: Android Splashscreen done right

Normally, webview loading is a little slow. And if you create the splashscreen as a separate activity, it won't solve the problem of webview loading slow. The above example use "SplashDialog", which will load webview at the same time as the splashscreen.

*Note: the above orientation handling doesn't seem to work with jquery mobile

0 comments:

Post a Comment

Please feel free to use any font to comment :)