My app is screen_orientation_portrait,but when I opened camera,the picture in my camera is 90degreed rotated.
So I tried to add "android:screenOrientation="landscape",in demo ,it is ok,but when I use it in my app,the camera activity opened and the app turned to be screen_orientation_landscaped,and the camera activity closed.
I reallied it is because when change the screen_orientation,the activity is going to reopen it self,but in my app,it dose not open after closed.What I can see is my ActivityGroup.
So can I just made my camera activity not reopen after the orientation is changed?
add this to your activity in manifest
android:configChanges="orientation|keyboardHidden"></activity>
Related
I have the following problem on an Android 4.4.2 device, the Samsung Galaxy S4 Mini.
If I take a photo with the back-camera, my app kind of restarts and is in an inconsistent state. My main activity is recreated.
I tracked the problem and it seems that this strange behavior happens because the camera app rotates my app.
This is strange because I setup my app to work only in portrait mode. No O
orientation change is though considered.
Android correctly recognizes this misbehavior and rotates my app back, but exactly that's the problem. On orientation change the activity is recreated and my fragments state is lost.
I don't get this behavior on other phones and also when making a photo with the front camera on the S4 mini.
In my opinion that's a bug either in the android version or in the camera app.
See the following log for details:
Selfie Camera (OK):
Main activity onCreate
Fragment onCreate
User takes a photo and confirms it
onActivityResult called
Back Camera(NOT OK):
Main activity onCreate
Fragment onCreate
User takes a photo and confirms it
Fragment onCreate
Main activity onCreate (app rotated)
onActivityResult called
Fragment onCreate
Main activity onCreate (app rotated correctly back on portrait)
How can I deal with this situation?
Is there a way to stop the camera app doing this.
Or is this a known issue and a workaround exists?
You can use surface view SurfaceView Documentation which opens a camera inside the activity instead of using the camera application.
I am launching camera intent from my android application using this answer (I need user to be able to choose image from camera or from gallery)
But it seems that my whole app is recreated - activity's onCreate is called, and one of the classes, that is a singleton, has toString() value, that differs from the value before camera launch.
Here is also my activity description from android manifest:
<activity
android:name="xxx"
android:theme="#style/NoActionBarTheme"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name">
</activity>
Any ideas what is going wrong?
Make sure uncheck "Dont Keep Activities" from Developer Options in Settings.
Also check your manifest and code if your activity has correct launchMode.
On some devices(i observed samsung s3), when launch camera app, device orientation is changed to landscape & again to portrait when select captured photo to return to our app. Our activity is re-created again & we end up as just started activity.
In this case, you have to implement following pair of callbacks for activity. OnSaveInstanceState() & OnRestoreInstaceState().
You can save member variables & restore them back when come back to your activity from camera app.
e.g. imagePath (location you give for saving camera picture) can be saved & restored.
When i press Home key and then application Icon then it will show me last activity but it will always start the first activity that is from main->first activity.Where main is the launch activity.But if i restart the application then it will work perfectly.So can anybody know why it will work after restart and not at starting?
My Application flow is like this way.Application class->Main activity->Tab activity with5 tabs and each tab open separete activity.edit I restart application like this way: in eclipse again run the application and in phone from settings->application->manage applications->myapplication->force close.Then click on application icon. Sipdroid is launch activity and welcome is first activity which has 5 tabs.
This is my menifest.xml file
Its solved by just removing the android:launchmode="SingleInstance" tag from manifest file.
Here is an interesting one...
I have an application I am writing for devices running android 2.3.3 and above.
It has a main activity which calls the camera via an Intent.
If the user clicks a button to launch the camera; then takes a picture; then clicks "Done" to return to the main activity - the application works fine and displays the new picture in an imageview on the main activity.
however, if the user uses the main activity in portrait orientation; then clicks the button to open the camera intent and changes the orientation to landscape; then click done to return to the main activity - the application crashes
but then...however, if the user uses the main activity in portrait orientation; then clicks the button to open the camera intent and changes the orientation to landscape; then changes the orientation back to portrait (in the camera) before clicking done to return to the main activity - then the application continues to run normally.
Stuff I have tried:
I have changed the manifest file to force the application (main activity) to be oriented in portrait (I have also removed this)
I have added this line to the main activity in an attempt to handle the re-drawing of the activity on it return from the camera intent:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
In the debug window I get errors describing nullpointer exceptions - I think this is because the views are no longer there after an orientation change for the image to be passed into unless the orientation is the same as when it was left.
I'm a bit stuck so would appreciate some advice.
When your screen orientation changes, your Activity is destroyed and recreated in the new orientation. So any variables that gained a reference during the life of the Activity will no longer refer to anything, and if you then try to access objects they refer to without re-assigning them values, you'll get a NullPointerException.
The method onSaveInstanceState() is used to save temporary data between configuration changes. This creates a Bundle which is passed to onCreate() when the Activity starts up again.
Without any code, I don't know if that's your problem, but it's worth a look.
See http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges for more information (and more accurate information than I've provided, no doubt).
hey i am not sure but try to put this property in manifest file hopefully it should work
android:configChanges="orientation|keyboardHidden"
Some Android devices like Samsung S3 and S4 have default camera surface view in Landscape mode.
When you call camera and capture image and come to your application, whether you had set orientation PORTRAIT it will first open in LANDSCAPE mode and then changes to PORTRAIT mode.
Its Android OS behaviour.
Due to this Activity Re-Creates it self. At that time you are getting Null Pointer Exception.
You can handle by setting configChanges in menifest file.
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
and you can store the data temporary in onSaveInstanceState() rightly said by #Spinner in his answer.
I have activity with:
android:screenOrientation="portrait"
and code:
if(blah blah blah)
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
in activity onCreate.
1. When test on smartphone "setRequestedOrientation" causes destroy activity and create again with desired screen orientation.
2. When test on tablet device this code runs only once activity. After "setRequestedOrientation" it just continues without destroy and create again activity. This happens when start code without debuger or without breakpoint in onCreate. If I stop in onCreate function - I see in logs - destroying and onCreate again.
How to catch specific situation with tablet?
UPDATE:
- Problem with tablet occurs when 'Orientation lock' if off. If 'Orientation lock' is enabled program works in same way as in smartphone.
UPDATE2:
- Is it possible to set preffered screen orientation to whole application. So when activity starts to know desired orientation. This will make unnessesary call 'setScreenOrientation' and avoid second activity creation.
After whole day spent with this issue I made following changes in my application:
1. Every activity /without first/ are declared as android:screenOrientation="behind".
2. In first activity I set preferred screen orientation using user selected mode /from my menu.
3. I call setRequestedOrientation only when user changed mode in my menu options.
This causes activities to be created only once. Finaly :)
No.. you cannot set preffered screen orientation for whole application... instead you should call for setScreenOrientation in respective activies only... Refere this link here...
You can set
<activity ActivityName = "test_activity"
android:configChanges="orientation">
</activity>
in your android manifest file. It will not allow activity to restart on orientation change but onconfigurationchange will be called normaly.
Later you can getdisplayorientation in onconfigurationchange and set whatever you want.