开发者

how to handle orientation in android 2.3 version?

开发者 https://www.devze.com 2023-04-12 19:30 出处:网络
I would like to handle screen orientation in a sample application.I have implemented code as follows:

I would like to handle screen orientation in a sample application.I have implemented code as follows:

WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);

    if(wm.getDefaultDisplay().getOrientation() == 1)
     {

        Log.v("Orientation111", "Condition true in if black");


     }
    else
    {

    开发者_运维问答    Log.v("Orientation222", "Condition truein else black");


    }

i am lunching the application in android 2.3 version API level is:9.when ever i change the orientation i can execute "if" black from potrite to land scape.Next i change the orientation from land scape to potrite then i am not getting if black.It is happenning with android 2,3 version.How can i handle this issue?

plzzz any body help me...


Editing Answer based on feedback:

On Android all the existing UI elements (like button, textBox, checkBox etc) gets destroyed and redrawn on orientation changes. This also means that state of UI elements will get lost on orientation change (like a checked checkBox may get unchecked). To handle such cases your application will need to be notified about such things (here orientation change). Android provides the facility to listen such events via onConfigurationChanged method. You will need to override this method in your activity class and also declare the need to override this in your activity manifest by adding android:configChanges="orientation" attribute to your activity declaration. Now onConfigurationChanged will give you the opportunity to persist/restore the state of your application. You can also add your log messages code in this method in order to see the current orientation mode.

See this tutorial for more details.

0

精彩评论

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

关注公众号