I have created an App, when my app start its shows a image and I have set ScreenOrientation="sensor" in manifest.
but when I rotate my device my app crashes.
sometime its shows image in portrait mode or landscape mode.
can anybody please help me.
how can I set orientation of screen according to sensor.
Thanks
your activity in your Manifest file is::
and also stop or intrupted yout thread while completing the work
Main problem is your background Thread is running and when you change orientation the new view is generated and try to access old view so app crashes....
<activity android:name=".SensorTest"
android:windowSoftInputMode="adjustPan" android:screenOrientation="sensor"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
Related
I'm developing an Android app that needs to validate user with reCaptcha and I'm occurred on strange behaviour: if screen orientation is in landscape, tapping button that fires reCaptcha API orientation changhes to portrait and then back to landscape.
There is a way to fix this? I'm not found any documentation about this...
Here is API from SafetyNet lib:
SafetyNet.getClient(this).verifyWithRecaptcha(ReCaptcha.RECAPTCHA_APP_KEY)
Version:
implementation("com.google.android.gms:play-services-safetynet:17.0.0")
When you rotate your activity gets refreshed
You need to declare android:configChanges="orientation|screenSize" in activity tag
<activity
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
this will avoid activity refresh
I hope this will help
I'm developing a game that runs in a wrapped webview for Android devices. Everything is working as expected--in this case, I have locked my view to landscape orientation, and prevented the device from restarting the activity if the phone is rotated.
However, if I put my device to sleep and then unlock it, I see my application in portrait mode for a moment, until my device re-orients to landscape. This behavior makes sense, since a phone is naturally used in portrait orientation, but I don't want my activity to switch from landscape.
If I start any other game, by which I mean those presumable written in native code, that is locked into landscape mode, and then lock and unlock my phone, the game doesn't do the same quickly-switch-from-portrait-to-landscape dance.
What am I missing?
In MainActivity I have
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
in several places, including onConfigurationChanged, onWindowFocusChanged, onPause, and onResume.
Here is how my activity is defined in my AndroidManifest
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:screenOrientation="sensorLandscape"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Thanks for any help/advise!
-J.L.
You forgot to remove sensor from the screenOrientation tag. Try this:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
the app still shows as the incorrect orientation for a split second when the phone is unlocked.
Did you move setContentView(R.layout.main) to the onResume, AFTER where you put your orientation code? I would try setting the orientation, then the setContentView()
I'm building an android application, which has a service, the service keeps running even if the app is killed by the user, I use this service to do some calculations, and send and receive data to the server, sometimes I use this service to relaunch the application, my application uses only landscape orientation. I used this code in AndroidManifest.xml:
<activity
android:name="com.myapp.MainActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
However, when the app is killed by the user, and the user locked the mobile, it works, but it runs in portrait orientation.
I use this piece of code to run the app in the service:
bringToForegroundIntent = new Intent(AppContext.getContext(), MainActivity.class);
bringToForegroundIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
Intent.FLAG_ACTIVITY_NEW_TASK);
locSaveService.startActivity(bringToForegroundIntent);
I tried to solve this issue by deleting portrait XML layout from the app, but it throws an exception. Any Ideas?
Thanks
My app seems to restart when it detects an orientation change. Well not really.
I only have portrait orientation enabled though.
In log cat I can see that my app is still doing calculations, but my progress dialog disappears.
What is going on?
In my manifest file this is my activity.
<activity
android:name=".xxxActivity"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Is there a specific reason why you're listening for the orientation change with android:configChanges="orientation"?
If not, remove that and I suspect your problem will go away.
add this right after the super call
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Better to change configChanges to
android:configChanges="orientation|keyboardHidden"
I guess, that activity is restarted, because you forgot to add onConfigurationChanged(Configuration) method in your activity.
http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged(android.content.res.Configuration)
It can be empty but shold be in the activity.
Also android:screenOrientation="portrait" is not needed.
my android application crashes and shows force close when i tilt the mobile phone. is there any suggestions that i can remove such problem? By the way i am developing a LBS application which uses the google maps (MapView).
I have a splash screen and then shown a ListActivity as below :
<activity android:name=".Splash" 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=".Home" android:label="#string/app_name" android:configChanges="orientation" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="com.nepways.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
what is wrong with my declaration, the splash screen loads and list activity is also whown correctly but when i change the orientation the application is closed. Please help me.
When you change your orientation the activity is restarted
look at the logcat to see what exception causes your application to FC
You can change your manifest to disable activity restarting by customizing configChanges, if you stil have the problem override onConfigurationChanged() to fix what is generating this exception (like initialize something that may cause a nullpointer)
First of all as it is said the app is restarting (or as it is said in reference redrawing) each time when you change orientation.
To block it in your manifest file in activity you have to put this line which describes the activity orientation:
<activity android:name=".Splash"
android:label="#string/app_name"
android:screenOrientation="portrait">...
And about this buttons, or keymaps. Telling the truth Ive got thise warnings sometimes but it doesnt change anything in my app. So first change the orientation settings and then it should work correct.
If you want use other screen orientation remember to check here:
http://developer.android.com/guide/topics/manifest/activity-element.html
If you want to avoid restarting your activity on orientation change, you can put this in the activity in the manifest file:
android:configChanges="orientation"
Otherwise, we will need to see more code, and a stacktrace.