So I put screenOrientation="nosensor" (also tried portrait, as I want every activity only to be able to be vertically) in manifest file, but it only works in MainActivity, but when I change to another activity, it can rotate the page again, why is this happening, and what should I do?
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.frisbeecaddy">
<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=".ActivityNewGame2"></activity>
<activity android:name=".ActivityResume" />
<activity android:name=".ActivityNewGame" />
<activity android:name=".ActivityNewCourse" />
<activity android:name=".ActivityCourses" />
<activity android:name=".ActivityPlayers" />
<activity
android:name=".MainActivity"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Put this line in all of your activities.
android:screenOrientation="nosensor"
for example in your code:-
<activity android:name=".ActivityNewGame2"
android:screenOrientation="nosensor"/>
<activity android:name=".ActivityResume"
android:screenOrientation="nosensor" />
<activity android:name=".ActivityNewGame"
android:screenOrientation="nosensor"/>
<activity android:name=".ActivityNewCourse"
android:screenOrientation="nosensor"/>
<activity android:name=".ActivityCourses"
android:screenOrientation="nosensor"/>
<activity android:name=".ActivityPlayers"
android:screenOrientation="nosensor"/>
You have to specify the orientation for every activity.
android:screenOrientation="nosensor"
Related
IDK why it's happening, there's an intent filter in there.
I think I'm missing a tiny problem, that another point of view can detect faster/
thanks!
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.caloriecalculator">
<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=".Login"></activity>
<activity android:name=".MainActivity" />
<activity
android:name=".Register"
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>
</manifest>
Sorry for this million times repeated answer, (Im a newbe in Andoid), but I cannot achieve to stay layout in Portrait orientation only. I've tried to set it with recommended
android:screenOrientation="portrait"
in Mainfest.xml (for Activity, (have just one)), but it doesn't work.
Anyone knows why ?
Below is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.leo.vj">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name_2"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
It seems you declared your main activity wrongly.Try this
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name_2"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
You missed configChanges. In the manifest, set this for all your activities:
<activity android:name=".YourActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"/>
The above solution will work.
You have missed the config changes..
If you want to acheive through Code.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Attribute name mismatch screenOrientation is the correct one
Please see below
android:screenOrientation="portrait"
The Problem is there is an extra '>' in end in declaration
<activity
android:name = ".MainActivity">
android:screenOrientation = "portrait">
Change the Activity Declaration in to :
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.testlocalserver">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".confirmActivity" />
<activity
android:name=".confirmActivity"
android:label="#string/title_activity_confrim"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
Below is the error:
error:at android:name=".confirmActivity"
duplicate registration for activity
android.testlocalservice.confirmactivity
I don't why this is happenning and i read some answers and says select the mode !!
how can i set the mode of activity ,why ?
As the error says, you have two activities with the same name.
Remove one of them:
<activity android:name=".confirmActivity" />
<activity
android:name=".confirmActivity"
android:label="#string/title_activity_confrim"
android:theme="#style/AppTheme.NoActionBar"></activity>
I'm trying to move to a new activity from a selected option from a menu on my main screen. The code for doing this is
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_settings:
Intent settingsIntent = new Intent(this, SettingsActivity.class);
this.startActivity(settingsIntent);
break;
The activity is set up in my manifest file as below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test_controller">
<uses-permission android:name="android.permission.BLUETOOTH" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name=".SettingsActivity" />
The app crashes as soon as it hits the startActivity line with error
Unable to find explicit activity class {com.test.test_controller/com.test.test_controller.SettingsActivity}; have you declared this activity in your AndroidManifest.xml?
I've been away from Android for quite a while so I can't understand why is it putting the package name in twice? I've checked my settings and the App Id is the same as the package name in the manifest so what am I doing wrong?
Add this </activity> tag after <intent-filter> so system will consider them two activities.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> // add this tag here
<activity android:name=".SettingsActivity" />
Declare your SettingsActivity in your android manifest:
<activity
android:name=".SettingsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
Check Manifest file. The <activity> tag for .MainActivity is not closed.
Your Manifest file should be looks like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test_controller">
<uses-permission android:name="android.permission.BLUETOOTH" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>// add this
<activity android:name=".SettingsActivity" />
Hope it helps!!
I have created an simple app with a few activities. After successful installation I can't open the app. I can just see it in device's apps.
Yes of course a read all the answers telling "You have to set launcher activity". But I set launcher activity.
Here is AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.jacon.davodani"
android:versionCode="0"
android:versionName="0.1">
<application
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/Theme">
</application>
<activity
android:name=".activities.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.SearchActivity"
android:label="#string/search_activity">
</activity>
<activity
android:name=".activities.CustomerActivity"
android:label="#string/customer_activity">
</activity>
<activity
android:name=".activities.CreditActivity"
android:label="#string/credit_activity">
</activity>
<activity
android:name=".activities.PrintReceiptActivity"
android:label="#string/print_receipt_activity">
</activity>
<activity
android:name=".activities.ProductActivity"
android:label="#string/product_activity">
</activity>
Never before happened to me... Can you give me some advice? Thanks a lot
All your activities are required to be defined within the <application> tag.
<application
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/Theme">
<!-- Add activites here -->
</application>
Your manifest should look like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.jacon.davodani"
android:versionCode="0"
android:versionName="0.1">
<application
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/Theme">
<activity
android:name=".activities.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
...
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.jacon.davodani"
android:versionCode="0"
android:versionName="0.1">
<application
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/Theme">
<activity
android:name=".activities.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.SearchActivity"
android:label="#string/search_activity">
</activity>
<activity
android:name=".activities.CustomerActivity"
android:label="#string/customer_activity">
</activity>
<activity
android:name=".activities.CreditActivity"
android:label="#string/credit_activity">
</activity>
<activity
android:name=".activities.PrintReceiptActivity"
android:label="#string/print_receipt_activity">
</activity>
<activity
android:name=".activities.ProductActivity"
android:label="#string/product_activity">
</activity>
</application>
</manifest>
try Replacing your manifest with this..
Change your AndroidManifest.xml structure to -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.jacon.davodani"
android:versionCode="0"
android:versionName="0.1">
<application
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/Theme">
<activity
android:name=".activities.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.SearchActivity"
android:label="#string/search_activity">
</activity>
<activity
android:name=".activities.CustomerActivity"
android:label="#string/customer_activity">
</activity>
<activity
android:name=".activities.CreditActivity"
android:label="#string/credit_activity">
</activity>
<activity
android:name=".activities.PrintReceiptActivity"
android:label="#string/print_receipt_activity">
</activity>
<activity
android:name=".activities.ProductActivity"
android:label="#string/product_activity">
</activity>
</application>
</manifest>
All activities tag must be placed inside <application> tag and it should be placed inside <manifest> tag.