开发者

Android Splash Screen Bug

开发者 https://www.devze.com 2023-02-04 00:35 出处:网络
I display a splash screen for a开发者_如何转开发bout 3 seconds before my first Activity is called. Splash Screen is also an Activity, after 3 seconds it finish()es and starts FirstActivity.

I display a splash screen for a开发者_如何转开发bout 3 seconds before my first Activity is called. Splash Screen is also an Activity, after 3 seconds it finish()es and starts FirstActivity. Also I have set screen rotation of splash Activity to portrait view.

Now when I test my app it works fine, but during those 3 seconds of splash screen if i change screen rotation, my First Activity is called two times.

Is there any way / code snippet that could help me open my First Activity only once, despite screen rotations when Splash Screen Activity is at foreground. ? Thanks for helping :)


It's not really a bug. When you change orientation the current activity is created again, hence why your SplashActivity is called twice.

I wrote a blog post about handling orientation changes manually; http://c0deattack.wordpress.com/2010/12/25/dealing-with-screen-orientation-changes-manually/


I also had this 'bug'. Here it describes how I solved it: Activity reloads when orientation changes in Android


I think your thread of splash screen gets call again one more time.

So simply set a flag to check screen rotated or not. If yes than do not call this thread again. eg.

boolean yourScreenRotationFlag=false;

if(!yourScreenRotationFlag)
{
    // your splash thread code
}

and on rotation of screen set this flag to true.


you can solve it by add this xml attribute to the Splash Activity in the Mainfest

android:configChanges="orientation|keyboardHidden|screenSize"

it prevent your activity from Re-create when orientation occured

0

精彩评论

暂无评论...
验证码 换一张
取 消