I have an Activity where the 1st Fragment (whose orientation is locked) solicits input from a user. This data is used to determine how to orient the 2nd Fragment. This orientation will also be locked.
I am guessing I will have to make a call to setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) either from the Activity or the 2nd Fragment.
My question is where best to do this. Does it really make a difference? Can this action be performed w/o undergoing an Activity restart?
If changing the setRequestedOrientation state requires the screen to rotate then it will restart the activity.
For example if you request ActivityInfo.SCREEN_ORIENTATION_PORTRAIT while the screen is in landscape, it will restart.
However it will not restart if the phone is already in that orientation.
I have one activity which i am using as host for calling all my fragments.I am using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) for setting screen in landscape mode.But problem is that it is making every fragment in landscape mode because their is only one parent activity for all of them.I can not use android:screenOrientation="landscape" because this will also work the same.
I want one of my fragment to be displayed always in landscape mode and remaining fragment as according to device orientation.Is their is another ways for doing it?
If you wanna show one specific Fragment in landscape you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
in the onCreate() of your Fragment.
In this Fragments onPause() f.e. you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
which is the default value and enables screen rotation changes.
I have a problem for screen orientation on Android development.
I have two activities and one is set like this: (on AndroidManifest.xml)
android:screenOrientation="portrait"
and the other one is set like this:
android:screenOrientation="fullUser"
And here's the application flow:
Start Application -> 1'st activity started
-> Click a button -> a fragment started
-> Click a button -> 2'nd activity started
And one more thing you have to know is that 2'nd activity has translucent configuration meaning behind fragment is visible, but not focused.
The problem is, when I turn on the screen rotation sensor, and rotate the device,
2'nd activity is rotated properly but behind fragment also re-created.
What I expected is that fragment is remained portrait, and only second activity
re-created landscape orientation.(I think 1'st activity also re-created but we can't
sure because it is hidden.)
I wanna know this is right behavior, and why it works like this? (give me documentations, or something reasonable reasons, etc.)
How should I do if I want fragment remains portrait and second activity changed landscape?
I'm making an app for 7" tablets. I'm following the example given here http://developer.android.com/guide/components/fragments.html.
There are two fragments.
TitlesFragment containing list
DetailsFragment containing webview to show result on click of an item in list
In landscape mode they are one next to another. Click in TitlesFragment list item will show details in the DetailsFragment. All in the same activity.
In portrait mode however, clicking in TitlesFragment opens a new Activity called DetailsActivity that has DetailsFragment which shows the details.
When he's on DetailsActivity switching to landscape mode finishes DetailsActivity and he's back on TitlesActivity where he will see the split view like explained before.
Problem now is -
Suppose he's on DetailsActivity in portrait mode. He starts a download and a dialog with active download progress bar is being shown. Now he switches to Landscape mode. The details activity finishes and my download dialog is gone. How can I handle this case?
This seems to be a common problem but I couldn't find a solution after searching. Can anyone help me?
Suppose he's on DetailsActivity in portrait mode. He starts a download
and a dialog with active download progress bar is being shown. Now he
switches to Landscape mode. The details activity finishes and my
download dialog is gone. How can I handle this case?
I'm assuming that the download continues(probably in a Service?!) even if the user finishes the DetailsActivity by switching to landscape. In this case you could let the landscape activity(which will hold both fragments) know about this and indicate somehow that the download is still in progress and an indicator should be shown. That indicator could be a dialog/ProgressBar on top of only the DetailsFragment for that position(so the user can still fully use the app) or on the entire screen.
Or you could lose the dialog and simply show a notification letting the use know a download is in progress without the need for the dialog. If the download is important and the user should wait this is not an option.
I'm developing an android app, and not understanding the back button.
There is an Activity (say A1) from which by clicking a button, user goes to another Activity (say A2). Once the user has finished with A2 activity, he clicks back-button, to go back to previous activity A1. All the docs say, A1 will onResume() at this point.
And it does. However, if I am in A2, and change the screen orientation (from landscape to portrait or vice versa), then something very different happens. The A2 activity lays itself out again, into the different screen orientation as expected. When I press BACK now, the Activity A2 lays itself out again (no change to screen orientation). Pressing BACK again, again causes Activity A2 to lay itself out again. A THIRD press on back takes you back to Activity A1.
What am I doing wrong here, what am I missing? Thanks
Peter
My question was not phrased completely correctly. I slightly simplified the case. I am using a Spinner, not a Button, to transfer to the next Activity.
Spinner (and Gallery) have a gross bug, not mentioned in the docs - the OnItemSelectedListener event handler is called when a user physically clicks the spinner control, and also when a spinner is first laid out by the framework code. Your spinner handling code must therefore determine if an event was triggered by a user selection or by the spinner being laid out. The easiest way to do this is to make the first item in a Spinner always be "no selection made yet", and to ignore all events on that selection.
See Android Spinner selection and similar posts.
In my case, the orientation change caused the spinner to get laid out again, and I thus got two events from it, the first the layout event, the second from the previously selected entry. And that caused a bogus second activity to be started, and that meant that 3 presses of the back button were needed to "get back" to the first Activity. It was actually going back on the first press, then the spinner fired a layout event and a regular event putting me in the second Activity twice. That wasn't seen on the screen, but was seen using log messages.
When you change orientation, the current Activity is destroyed, and a new Activity created/started.
When you change orientation and press the back key, the previous Activity is popped from the top of the paused stack, destroyed, and a new version of that Activity created/started.
When you change screen orientations, the Activity in the old orientation is never kept. It will be destroyed immediately, or if it is lower down the Paused stack, it will be destroyed when it comes to the top.
you're not handling configuration changes. Check out this link it may help you.
When you change your orientation from portrait to landscape or landscape to portrait and if you are not handling configuration changes, then the activity is recreated.