unexpected behaviour when orientation changes from portrait to landscape mode - android

I have the following manifest file for my app
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.netserv.Pungry"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:maxSdkVersion="17"
android:minSdkVersion="5" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!-- <meta-data -->
<!-- android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" -->
<!-- android:value="true" /> -->
<meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="a150cb2e31846cf" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/bghomescreen"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.netserv.Pungry.Home"
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=".LocationbyCities" >
</activity>
<activity android:name=".General" >
</activity>
<activity android:name=".RestaurantsList" >
</activity>
<activity android:name=".Quickbite" >
</activity>
<activity android:name=".AdvanceSearch" >
</activity>
<activity android:name=".SelectMenu" >
</activity>
<activity android:name=".RestaurantDetails" >
</activity>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="orientation|uiMode|keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout" />
<receiver android:name=".UpdateReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
</application>
</manifest>
When I load the app to device it is working fine in portrait mode. But when i change from portrait to landscape mode it is transisting to some different activity which is not the correct one and some times the app itself will close.
I have defined layout's in layout for portrait and layout-land for landscape mode.
I don't want to fix the orientation to portrait mode.

Try overriding these two methods. It had solved my problem.
#Override
protected void onSaveInstanceState(Bundle outState) {
webView.saveState(outState);
super.onSaveInstanceState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle inState) {
webView.restoreState(inState);
super.onRestoreInstanceState(inState);
}
Hope that helps.

Just use the configChange attribute in your all activities
<activity
android:name="com.netserv.Pungry.Home"
android:label="#string/app_name"
android:configChange="orientation|screenSize" > <!-- like this use this attribute in all activities -->

Related

Cannot install application in Android Tablet

I am using Android Studio to develop an app which used Camera2 API. I can run the app in Google Nexus 9, however the app is not installed in the device and I cannot access it once I close the app. What am I doing wrong ?
Here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera2.full" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MapActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.map" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="test.camera.main" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
add the following to your < activity > in your AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
EDIT: added sample
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.android.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat" >
<activity
android:name=".ActFirst"
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=".ActSecond" >
</activity>
</application>
</manifest>
While running my app, I thought I had the same problem.
The problem in my app was the app_name in the strings file was different that what I thought it is. So Basically I was looking for app "X" while the name i gave is "Y".
Maybe you have the same problem.

The <activity> element must be a direct child of the <application> element

I just wanted to launch my application, but it always fails and gives me this error. Before, it would just install the .apk file, but now it just fails to start at all. I just began and was following the Android Developing tutorial.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myfirstapp.MainActivity"
android:label="#string/app_name" >
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</meta-data>
</activity>
</activity>
</application>
</manifest>
You can't have nested activity tags inside your Manifest, fix this issue and it should work.
YES - for example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.camera" />
<application
android:icon="#drawable/icon" android:label="#string/app_name">
<!-- Boot window -->
<activity
android:name=".ServicesDemo" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Second window -->
<activity android:name=".MainActivity" android:label="#string/app_name"
android:parentActivityName=".ServicesDemo" />
<!-- Second window -->
<activity android:name=".MyWall" android:label="#string/app_name"
android:parentActivityName=".ServicesDemo" />
<!-- Second window -->
<activity android:name=".MyRotations" android:label="#string/app_name"
android:parentActivityName=".ServicesDemo" />
<!-- Second window -->
<activity android:name=".MySetting" android:label="#string/app_name"
android:parentActivityName=".ServicesDemo" />
<receiver
android:enabled="true"
android:name=".IntentReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.HEADSET_PLUG" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service android:enabled="true" android:name=".MyService" />
<service android:enabled="true" android:name=".MyNewpic" />
</application>
</manifest>
You don't nest Activities in other Activities. This is how it should look like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myfirstapp.MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</meta-data>
</activity>
</application>
</manifest>
Do read the Android docs for the AndroidManifest.xml file

App change portrait orientation to landscape on motorola xoom

We are developing an app, what is changing the hard coded orientation portrait to landscape on the 2nd launch.
We have screenOrientation="portrait" in all activity definitions in the manifest file.
Any idea how to resolve this?
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myproject"
android:installLocation="auto"
android:versionCode="13"
android:versionName="12.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#string/icon"
android:label="#string/app"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<meta-data
android:name="com.mobclix.APPLICATION_ID"
android:value="XXXX" />
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />
<activity
android:name=".xyactivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />
<activity
android:name=".xyzActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".abactivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name="com.mobclix.android.sdk.MobclixBrowserActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
</application>
</manifest>
For restricting to only portrait orientation you need to put this code for every activity during declaration in your manifestfile
<activity android:name="MyApp" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"></activity>

No resource identifier found for attribute 'uiOptions' in package 'android'

<?xml version="1.0" ?>
<manifest android:screenOrientation="landscape" android:versionCode="3"
android:versionName="3" package="com.tablet3" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="11" />
<!-- TI_MANIFEST -->
<application android:debuggable="false" android:icon="#drawable/appicon"
android:label="actiobar" android:name="actiobarApplication">
<!-- TI_APPLICATION -->a
<activity android:configChanges="keyboardHidden" android:screenOrientation="landscape"
android:label="mob" android:name=".actiobarActivity" android:theme="#style/Theme.Titanium">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiActivity"
android:screenOrientation="landscape" />
<activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiTranslucentActivity"
android:screenOrientation="landscape" />
<activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiModalActivity"
android:screenOrientation="landscape" />
<activity android:configChanges="keyboardHidden" android:name="ti.modules.titanium.ui.TiTabActivity"
android:uiOptions="splitActionBarWhenNarrow" android:screenOrientation="landscape"
/>
<activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"
android:screenOrientation="landscape" />
<service android:exported="false" android:name="org.appcelerator.titanium.analytics.TiAnalyticsService"
/>
</application>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
I get this error when i add uiOptions to my activity.
AndroidManifest.xml:22: error: No resource identifier found for attribute 'uiOptions' in package 'android'
I want the ActionBar to come down, so i am actually trying to uiOptions in my Activity.
This attribute was added in API 14, but you have specified targetSdkVersion 11

Android changes to be made in Manifest working with different packages

I have two packages and within them are multiple activities. After seeing the replies in stackoverflow, i have made necessary changes in manifest file, still the apk doesnt runs.
Here is my sample manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.user.login"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashActivity"
android:label="#string/title_activity_splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SucessRetrieveCredActivity" >
</activity>
<activity android:name=".ResetPasswordMessageActivity" >
</activity>
<activity android:name=".ResetPasswordActivity" >
</activity>
<activity android:name="com.xyz.stylist.search.ServiceMap" >
</activity>
<uses-library
android:name="com.google.android.maps"
android:required="true" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I have to import import com.hairologie.user.login.R; in ServiceMap activity, still it doesnt works. Earlier when ServiceMap and other activities were in same package, it worked just fine.
try this:
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".user.login.SplashActivity"
android:label="#string/title_activity_splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".user.login.SucessRetrieveCredActivity" >
</activity>
<activity android:name=".user.login.ResetPasswordMessageActivity" >
</activity>
<activity android:name=".user.login.ResetPasswordActivity" >
</activity>
<activity android:name=".stylist.search.ServiceMap" >
</activity>
<uses-library
android:name="com.google.android.maps"
android:required="true" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Write
android:name="com.yourpackage.activityName" in ManifestFile instead of
android:name = ".ActivityName"
it will solve the issue.
Change your package name in manifest to com.xyz
declare all the activities like
android:name=".stylist.search.ServiceMap"
android:name=".user.login.SplashActivity"
After that clean and build your project and run

Categories

Resources