i have one activity in my manifest.xml my activity is CPohonApp but in this activity i have 2 config
this is my manifest
<activity android:name=".pupuk.CPupukApp" android:configChanges="keyboardHidden|orientation"></activity>
and
<activity android:name=".pupuk.CPupukApp" android:screenOrientation="portrait"></activity>
when run this code is not work.
how to run two config in one name activity in manifest.xml?
thank you.
sorry for my bad english
Alex
Alex when you set android:screenOrientation="portrait" then your activity remains in portrait mode so no need to declare orientation configChanges. Try this.
If you have more than one configuration for particular activity then no need to declare it more than one time . Declare all those in that single activity.
<activity android:name=".pupuk.CPupukApp" android:configChanges="keyboardHidden" android:screenOrientation="portrait"></activity>
add the two configurations to single activity initialization
<activity android:name=".pupuk.CPupukApp" android:configChanges="keyboardHidden" android:screenOrientation="portrait"></activity>
Related
The title of this question is not exactly reflects my question I have trimmed it because it went too lengthy. Sorry for my bad English too.
Okay,
I am using a library which has an activity, I am using that activity in my app. The orientation of that activity is working fine in tablets i.e., both landscape and portrait but in phones it sticks to portrait mode.
When I have seen the Manifest file of that library its like
<activity
android:name="DrawingActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:finishOnTaskLaunch="true"
android:screenOrientation="unspecified">
In the thread Android Orentation Changes. I came to know it should like android:screenOrientation="fullSensor" to work.
Now I am trying to override the screenOrientation property of the activity as said here
using tools:replace attribute but still its not working. Please can anybody help me to solve this issue.
This is how I'm trying to achieve.
<activity
android:name="DrawingActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:finishOnTaskLaunch="true"
android:screenOrientation="fullSensor"
tools:replace="android:screenOrientation">
If my question is not clear/too broad please let me know I'll edit my question.
Regards
You can use tools:node="merge", for example:
<activity android:name="DrawingActivity"
android:screenOrientation="fullSensor"
tools:node="merge">
</activity>
this node will be merged with the existing one and overrides any duplicates.
for more details about this refer to https://developer.android.com/studio/build/manifest-merge#node_markers
<activity
android:name="DrawingActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:finishOnTaskLaunch="true"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation">
Dont use android:screenOrientation instead use screenOrientation
This will work:
tools:node="replace"
In your case it'd be:
<activity
android:name="DrawingActivity"
android:screenOrientation="fullSensor"
tools:node="replace" />
It will replace any attr added on the library which in this case will be 'screenOrientation' from 'unspecified' to 'fullSensor'.
Try this one:-
<activity android:name="DrawingActivity"
tools:replace="android:screenOrientation"
android:screenOrientation="fullSensor">
</activity>
Import library as module instead of using Gradle, so you can change Code
I am in trouble with Portrait and Landscape modes of my android application. So, I want to know how to restrict my application in anyone mode only. Thanks in advance to any reply with suitable answer and problem solving solution.
You can define your screen Orientation in your manifest file, activity tag
android:screenOrientation="landscape"
for more detail refer here.
add the below code in the activity tag of your manifest file...
android:screenOrientation="landscape"
Add android:screenOrientation to your activity tag in manifest file like below code:
<activity
android:name="com.packagename.YourActivity"
android:screenOrientation="portrait" >
</activity>
Try this:
<activity
android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden|keyboard"
android:screenOrientation="portrait" />
I want to run my app in portrait mode, I'm aware this isn't best practice but there are reasons to do this. and while I have disabled the rotation it still is able to rotate on some views will it doesn't on others.
I have this part of code in my Android Manifest:
<activity
android:name="<name>.app.MainActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|keyboard|locale|orientation"
android:screenOrientation="portrait">
I'm using fragments to show different containers depending on user input.
this is the only activity that has fragments.
I have tried a few solutions on this site. including setting portrait mode on by code
You can do it something like below.
After rootView in your java add this line
getActivity().setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // programmatically
For example:
View rootView = inflater.inflate(R.layout.activityxml, container, false);
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
And also in your manifest change it:
android:configChanges="orientation|keyboardHidden"
as
android:configChanges="keyboardHidden"
<activity
android:name="com.test.activity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden" >
try this code
<activity android:name="com.myActivity" android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation"
>
</activity>
use below code before super.onCreate.first line of code.it force activity to portrait(of course both side of portrait)
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
the code that you entered android:configChanges="screenSize|orientation" just force activity to don't miss it's stats on rotate(onCreate call just once and if rotate onPause will call)
add Android Manifest:
tools:ignore="LockedOrientationActivity"
android:screenOrientation="portrait">
Is there a way I can start activity in a specific orientation (programmatically) without having it to be recreated again? Right now if I call setRequestedOrientation from the the OnCreate and the orientation is different than the current then the activity is destoryed and restarted again.
Thank you
For me solution was to lock orientation of Activity
android:screenOrientation="locked"
, and now it depends only on setRequestedOrientation():
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="locked">
No restarting anymore.
You can set your orientation in Manifest file
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
If you don't want activity to restart, add configChanges for the activity in AndroidManifest.xml
<activity
android:name="com.myexample.SplashScreen"
android:configChanges="orientation|screenSize"
android:label="#string/app_name" >
and then call setRequestedOrientation to set orientation programtically.
But if you want to lock the activity to 1 orientation. It is good to set it in Manifest by adding android:screenOrientation="portrait"
I am developing an android application. If I close my application, my app available in the "Recent Apps" List. Now I don't want to show it in "Recent Apps". How can I remove it from "Recent Apps List" after closing my application programmatically. Please can you share your suggestions.
In you Manifest.xml, set the following to your Root Activity
<activity
android:name=".Your_Root_Activity_Name"
android:excludeFromRecents="true"
....
</activity>
Depending on the results, you might also have to use the android:noHistory="true" attribute. But not sure if it is required in your case.
For more information about this: http://developer.android.com/guide/topics/manifest/activity-element.html
Add excludeFromRecents="true" to your activity in AndroidManifest.xml:
<activity android:name=".MainActivity"
android:excludeFromRecents="true" ...
override the onResume methods in your other Activities and there destroy them and call the main Activity.
In your AndroidManifest.xml, use this for Activity:
<activity
android:name="Your Activity"
android:excludeFromRecents="true"
android:noHistory="true"
android:taskAffinity="">
</activity>