I have a pretty big problem with my TabHost. Although I have declared all of my Activities (Including my TabHost Activity) to ignore orientation and keyboardHidden, if I flip my Phone (Android 4.0) It still recreates the activity.
Here is a shortened version of my Manifest:
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".TabHost"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity1"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" />
<activity
android:name=".Activity2"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" />
<activity
android:name=".Activity3"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" />
</application>
I don't think that the code of the activities would help?!
If it would however, let me know and I'll post it too.
Kind regards
if you are trying to stop the rotation of the screen use following code in your AndroidManifest.xml for each activity.
android:screenOrientation="nosensor"
UPDATE
According to API when using android:configChanges="orientation|keyboardHidden"
"orientation"
The screen orientation has changed — the user has rotated the device.
Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.
so, if you are targeting API level 13 or higher you gotta specify screen size also.
Related
I am getting reports that my supposedly portrait app can be rotated to landscape mode on a Nexus 5X running Marshmallow. I don't have one to test on but why is this happening? Here is my activity in the manifest:
<activity
android:name=".app.MainActivity_"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Activity"
android:launchMode="singleTask"
>
</activity>
Try and change your tragetSDKVersion from Marshmallow to Lollipop.
It worked for me.
You must use this for the Activity!
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
and for the whole application you must use this code which will force the orientation not to be landscape
<application
android:debuggable="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
I am very new to android development with eclipse, and I encounter dozen of errors and problems. Here is the next one:
I am following an android tutorial given here in order to set up the action bar. In this tutorial is says to insert an activity as follows:
<activity android:theme="#style/Theme.AppCompat.Light" ... >
Can I just put this line into the xml manifest file?
<activity android:theme="#style/Theme.AppCompat.Light">
Or do I need to replace the '...' by something more useful?
Please read the docs: activity-element
The activity's name is required, so you would need to have:
<activity android:theme="#style/Theme.AppCompat.Light" android:name="MyActivity">
Other than that, you are not required to add any other attributes.
Although be sure to place the activity element within the proper place in your xml. It should be contained in your application block:
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light">
<activity android:name="MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Unless you really want your app to work under API levels under 3.0 then you have to add it like this.
android:theme="#style/Theme.AppCompat.Light"
Inside your already defined activity in your manifest (the one that has the intent filter and other declarations).
otherwise you dont have to add that at all.
This is one example.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and this is another
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme=#style/Theme.AppCompat.Light"" >
<activity android:name=".DetailActivity"
android:label="#string/app_name" >
</activity>
The second way you posted is just fine, be sure to close the activity tag so it looks like <activity android:theme="#style/Theme.AppCompat.Light"></activity>
Also, if you're using eclipse, it is easier to go into the AndroidManifest and under the Application tab scroll to the bottom where there's Application Nodes and then add your view from there. Eclipse will auto generate the correct code in the xml file.
I want to keep landscape mode always.
I Lock screen to portrait mode on Nexus7, I set android:screenOrientation="sensorLandscape" and android:configChanges="orientation|keyboardHidden"in AndroidManifest.xml, when I go to other activity and back to this activity, then the screen will rotate portrait and rotate to landscape again (Didn't call onCreate method again), but I don't want to rotate the screen in any situations, how to fix it?
I think this is the answere you're looking for:
stackoverflow.com/a/2730894/2249774
For All your Activities in the manifest set
android:screenOrientation="sensorLandscape" android:configChanges="orientation|keyboardHidden"
Example :-
<activity android:name="com.example.test.testActivity" android:label="#string/app_name" android:screenOrientation="sensorLandscape" android:configChanges="orientation|keyboardHidden"">
<intent-filter>
<action android:name="com.example.test.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Repeat this for all activities used in the manifest..
Try editing your AndroidManifest.xml to look like this
<activity
android:name=".YOURACTIVITYNAME"
android:screenOrientation="landscape" />
In your AndroidManifest file, try typing in the following code:
android:configChanges="keyboard|orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
example:
<activity
android:name="com.gaspar.slinfilipino.Quiz"
android:label="#string/title_activity_quiz"
android:configChanges="keyboard|orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
android:parentActivityName="com.gaspar.slinfilipino.SignLanguageMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.gaspar.slinfilipino.SignLanguageMenu" />
</activity>
I am using Samsung Galaxy Note to run a phonegap application.
When I take picture, I can see that screen rotates just before entering camera.
How can I disable this?
I have tried to force portrait orientation on both, the main thread & camera activity,
but those do not seem to work:
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:debuggable="true">
<activity android:name=".App" android:windowSoftInputMode="adjustPan" android:screenOrientation="portrait"
android:label="#string/app_name" android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.phonegap.DroidGap" android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<activity android:name="com.android.camera.Camera"
android:screenOrientation="portrait">
</activity>
</application>
You need to add the permission on the manifest:
<uses-feature android:name="android.hardware.screen.portrait" />
Doc android of balise uses-feature
For example, if your app requires portrait orientation, you should declare <uses-feature android:name="android.hardware.screen.portrait"/> so that only devices that support portrait orientation (whether always or by user choice) can install your app. If your application supports both orientations, then you don't need to declare either.
How do you take picture? If you are sending intent to fire up camera application you lose control about orientation changes. Also note, that before going to sleep and locking screen launcher forces your application into portrait with an butt-kick regardles of the settings or overriding methods. Most probably you can not and behaviour on other devices could be different.
Use android:configChanges="orientation|keyboardHidden" where you are setting screen as portrait.
There are 2 things here that should be taken into account. First, this
android:screenOrientation="landscape"
has no effect if in the java code there is something like this:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Then, there is this other method that could be bothering you:
mCamera.setDisplayOrientation(90);
This would rotate your camera preview.
Hope this helps!
I have an app that works only in portrait mode, and I have made the changes in my manifest file for every activity the orientation to be portrait. But when I rotate the device, the activity recreates again.
How to not destroy the activity?
For API 12 and below: add
android:configChanges="orientation"
Add "screenSize" if you are targeting API 13 or above because whenever your orientation changes so does your screen size, otherwise new devices will continue to destroy your activity. See Egg's answer below for more information on using "screenSize"
android:configChanges="orientation|screenSize"
to your Activity in AndroidManifest.xml. This way your Activity wont be restarted automatically. See the documentation for more infos
From the official document flurin said,
Note: If your application targets API level 13 or higher (as declared
by the minSdkVersion and targetSdkVersion attributes), then you should
also declare the "screenSize" configuration, because it also changes
when a device switches between portrait and landscape orientations.
So if your app targets API level 13 or higher, you should set this config instead:
android:configChanges="orientation|screenSize"
The right solution is
android:configChanges="orientation|screenSize"
Android documentation:
The current available screen size has changed. This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).*
I was messing this up for a little bit and then relized that inside the Manifest file I was putting the configChanges on the Application level and not on the Activity Level. Here is what the code looks like when it is correctly working for me.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Now that Android supports split screen ("multi-window" in Android parlance), you'll probably want to add screenSize|smallestScreenSize|screenLayout|orientation as well. So to handle rotation and split screen you'll want something like this in android:configChanges
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Look at this code in Floating Image. It has the most interesting way of handling screen rotation ever. http://code.google.com/p/floatingimage/source/browse/#svn/trunk/floatingimage/src/dk/nindroid/rss/orientation
write in manifest:
android:configChanges="orientation|screenSize|keyboardHidden"
and override this in activity that solved your problem:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}