Force "portrait" orientation mode
Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges
as noted below.
Example:
<activity android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"></activity>
This is applied in the manifest file AndroidManifest.xml
.
Note that
android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
is added in the manifest file - where the activity is defined.
If you are having a lot activity like mine, in your application Or if you dont want to enter the code for each activity tag in manifest you can do this .
in your Application Base class you will get a lifecycle callback
so basically what happens in for each activity when creating the on create in Application Class get triggered here is the code ..
public class MyApplication extends Application{@Override public void onCreate() { super.onCreate(); registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity activity, Bundle bundle) { activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// for each activity this function is called and so it is set to portrait mode } @Override public void onActivityStarted(Activity activity) { } @Override public void onActivityResumed(Activity activity) { } @Override public void onActivityPaused(Activity activity) { } @Override public void onActivityStopped(Activity activity) { } @Override public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { } @Override public void onActivityDestroyed(Activity activity) { } });}
i hope this helps.