initialize Activity by Orientation - Android Activity

Android examples for Activity:Activity Orientation

Description

initialize Activity by Orientation

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;

public class Main {
    public static void initialize(Activity activity) {

        int loadedOrientation = activity.getResources().getConfiguration().orientation;
        int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
        if (loadedOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        } else if (loadedOrientation == Configuration.ORIENTATION_PORTRAIT) {
            requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        }//from   w  w  w.  j  av a  2 s. c om
        activity.setRequestedOrientation(requestedOrientation);
    }
}

Related Tutorials