problem while changing the orientation in app - java

i have already posted my issue in SO and got an answer but i have a problem in that too
my former question is
"i have created a quiz game in my app. The game is to be played in portrait mode. After the game gets over the score is been calculated and its been showed in the score page when i click ok a pop up window appears and asks for the name. I have placed an option to share the result in facebook and twitter.
now when i enter the name and click ok, a page with score name and share button appears, if i click share it moves into facebook or the other, but if i change over to landscape mobe my app gets crashed."
i got a solution to add a line in manifest file
<activity android:name=".main"
android:configChanges="orientation" />
along with the following code in the class file
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
This answer helps me to move to next operation without crashing my app but the problem is when i change from landscape to portrait, the background image and text also gets changed to portrait and half the screen the seems to be a blank one and text or not appearing fully.
this is the same when changed from landscape to orientation. i want the image and text to be fitted to proper orientation.
this problem has not occured before entering those manifest and coding lines
pls give me a solution.

You could try an explicit definition of your layouts.
For example have two layout files, one for landscape and another for portrait. Android is intelligent enough to use the best available layout -> Read HERE
To handle screen orientation gracefully there is something more you need to do -> Read HERE

Related

Activity orientation change while in the background

The first activity(locked portrait orientation) has 2 buttons that both open the second activity but A button opens it in portrait and B button opens it in landscape orientation.
The problem is that when B button opens the second activity (which is in dialog configuration and the first activity is shown in the background) the first activity changes orientation with the second one, thus restarting.
The question is, A) Can i prevent first activity from changing orientation and B) Can i disable orientation change animation so that the screen doesn't look like turning from portrait to landscape but just becoming landscape instead?
P.S For the A) question i know how to use saved state but i want to avoid it.
Use Below Code in Manifest:
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
Edited:
Sorry there is no way to control the rotation animation. This is done way outside of your app, deep in the window manager where it takes a screenshot of the current screen, resizes and rebuilds the UI behind it, and then runs a built-in animation to transition from the original screenshot to the new rebuilt UI. There is no way to modify this behavior when the screen rotation changes

android Change orientation removing button

I've set android:configChanges="orientation|screenSize" on an activity to stop it restarting the activity everytime the orientation changes. Now this works fine but I think it's stopping the correct layouts from being used.
E.G. I have different layout folders for different orientations and sizes of screen. So if I start the activity in portrait, when I change the orientation to landscape, it's not using my landscape layout.
Also if I start the activity in landscape, when I change the orientation to portrait, it's not using my portrait layout.
Basically what I want the app to do is not start the activity again once the orientation changes, but use the correct layout when the orientation is changed!
I was thinking I could use the onConfigurationChanged method to explicitly change the layout in code?
Thanks for any input
when you use android:configChanges="orientation|screenSize" this tells to Android that you will maintain these changes by yourself - this means you have to change your layout (setContentView) and initialize it manually (set values of controls - EditTexts, Spinners etc.)
So What I've ended up doing is keeping android:configChanges="orientation|screenSize" in the manifest file. Doing it this way stops me being able to use my correct layout folders for portrait and landscape.
To overcome this issue, I override the onConfigurationChange method to set the correct information I needed for the activity to run as expected once the orientation changes. below is the code I've used:
#Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
setContentView(R.layout.hearing_test);
//Any other information needed for the activity to work correctly
}
Thanks for the help and guidance #mihail, helped me get to the bottom of the issue.
That is exactly why the Activity is destroyed and recreated: to apply new resources.
Do not use android:configChanges="orientation" if you have different layouts for portrait and landscape mode.

Change orientation without setRequestedOrientation

When I click a button in my App, the screen orientation will automatically go to landscape :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
The screen get to landscape successfully but it caused my onConfigurationChanged not working anymore.
I tried to use: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); but it makes no difference.
What should I do, to make the screen go to landscape, when I click the button, without turning off the onConfigurationChanged?Or do you have any other ways to accomplish this?
If you are using API13 or higher as your target,
in your manifest you need to add ScreenSize to your configChanges:
android:configChanges="orientation|screenSize|keyboardHidden"
That should do the trick!

Android Setting Up Splash Screen(Activity) Like Iphone Part2

After getting solution to call my splash activity only one time (Part1 Question), Now i have to set up my splash activity.
On My First Layout i want functionality like this :
Image One <--> Image Two <--> Imgage Three --> Second xml(Activity)
Also on every image their will be a page control that will indicate on which image is currently on layout(Like the attached screenshot)/ or can be any other way to show this.
That Means From Image one i can go to image two on scrolling to right(I can come back to image one on scrolling to left) From Image two i can go to Image Three on scrolling right(I can come back to image 2 from Image three if i scroll to left)But if i scroll to right from Third Image then i should get to my Second Activity and never return back on those images.
i.e
I want to have scroll view having those three images with the page controller then after we scroll down to the third/last image on further scrolling to right i want that my second activity should be loaded and the splash should never come up.
Can any one tell me any idea how this can be done.
To make splash sheet with scroll view and page control & switch to second activity when done scrolling.
I don't want animation i want it to work manually like scrolling/ or any other way to implement this.
Coding will be much appreciated.
To implement scrollable images like shown above use ViewPagerIndicator library given HERE. Its simple to integrate and will take few minutes. All you have to do is read the usage section in given link.
For switching activity on last page, simply implement onPageChangeListener described in link and check for page number.

How to implement an activity into another?

I don't know if it's a dumb question because it is one of my first apps.. but if that's the case, please also explain why!
If I create a Tab-Based Activity-Structure, I get nearly what I am asking for but only for Tabs. What I want is generally opening a second or even third activity in one main-activity which contains the main-interface.
Example: I have a Title-Bar and a little icon at the bottom-left corner for some reason during the whole app runtime. Now: How can I control them with the main activity and open at the same time some other activities/views into the existing interface? It should then be shown below the title bar and lying underneath the little icon (the icon is not really important, just fictional). Also it would be nice if I could add some fade in effects to these embedded activities/views. Is that somehow possible?
I currently only know, how to open activities each over another filling the whole screen, except in the case of tabs... maybe I only haven't inspected the tab structure enough.. however, I would be delighted about each answer!
Regards
What you are looking for, are Fragments.
Fragments can be used to fill a part of the screen, while doing something else entirely in a different one.
In your example you can create a main activity that contains two Fragments. One Fragment controls the title bar, the other one controls the main content area.
By replacing the current Fragment in your content area with a different one on the press of a button, you can achieve the behavior you are looking for. At least, that's how I did it in an app of mine containing a main content area and a music player. The music player stays in place while the main content changes.
Sadly I can't provide any example code right now, but here is a tutorialthat should help you get started:
Android User Interface Design: Working With Fragments

Categories

Resources