Android :: Handling Screen Orientation

Jul 6, 2010

My project is working fine when i hold my HTC device vertical.But the moment i rotate my screen 90degrees , it throws a force close error.Starts all over again, runs fine until i again change the orientation.How do i handle it ?

Android :: Handling screen orientation


Android :: Handling Screen Orientation Change During Activity Start

Mar 12, 2010

I'm trying to find a way to properly handle setting up an activity where its orientation is determined from data in the intent that launched it. This is for a game where the user can choose levels, some of which are int portrait orientation and some are landscape orientation. The problem I'm facing is that setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) doesn't take effect until the activity is fully loaded. This is a problem for me because I do some loading and image processing during startup, which I'd like to only have to do once.

Currently, if the user chose a landscape level:

the activity starts onCreate(), defaulting to portrait discovers from analysing its launching Intent that it should be in landscape orientation continues regardless all the way to onResume(), loading information and performing other setup tasks at this point setRequestedOrientation kicks in so the application runs through onPause() to onDestroy() it then again starts up from onCreate() and runs to onResume() repeating the setup from earlier

Is there a way to avoid that and have it not perform the loading twice? For example, ideally, the activity would know before even onCreate was called whether it should be landscape or portrait depending on some property of the launching intent, but unless I've missed something that isn't possible. I've managed to hack together a way to avoid repeating the loading by checking a boolean before the time-consuming loading steps, but that doesn't seem like the right way of doing it. I imagine I could override onSaveInstanceState, but that would require a lot of additional coding. Is there a simple way to do this?

Solution:

As per Daniel's answer, this was actually quite easy to fix. I just needed to make a few small changes. In my 'menu' Activity, where the player would choose which level to play, I just had to add an if/else check to choose which class would be started by my Intent. This was done with a simple int representing portrait or landscape, determined when the player selected a level. I then created a second class extending my 'GameLogic' class; this is the class which contained most of the code for the game itself, rather than the menus, instructions, etc.

public class GameLandscape extends GameLogic{}

Literally that simple and completely empty. That way it inherited all the code from my previous activity where I had already coded it to handle things differently depending on the orientation. Lastly I just had to add a line to the manifest stating that GameLandscape would always run in landscape, and GameLogic would always run in portrait.

View 2 Replies View Related

Android :: Handling Orientation Changes Yourself

Jun 3, 2010

From the documentation regarding the android:configChanges='orientation' attribute of the activity tag in the manifest:

Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.

Why does it say this?

In the case of threads and networking requests via a service API library, a request could be made with a reference to the original Activity, and then an orientation change could occur, leaving the thread pointing to the old Activity.

While this can be fixed, it's tedious and ugly compared to just handling the configuration changes yourself.

Why should it be avoided?

I guess I should also ask: would this be an acceptable reason for doing the orientation configuration changes yourself?

View 2 Replies View Related

Android :: Handling Orientation Changes In AppWidgets

Apr 18, 2010

We have created an AppWidget that takes user inputted text into an EditText and displays a calculated amount of text inside a TextView on the Home Screen. We calculate the amount of text based on the AppWidgetInfo.minWidth, minHeight attributes. We do this to simulate scrolling; we cut up the user-inputted text into chunks that will fit into the widget and swap them based on button clicks.

When we save the widget with the device in Landscape mode, it calculates the appropriate amount of text for Landscape mode and displays it in the widget. The problem is when the user changes orientation of the device to Portrait mode (without opening the widget and resaving the text), the calculated amount of text for Landscape mode is still displayed. This also happens in the vice versa case (the user is in Portrait and saves, etc.)

How can we tell our AppWidget to recalculate the amount of text displayed on screen orientation change? Is this possible? How would you solve this problem?

View 5 Replies View Related

Android :: WebView / Handling Orientation Changes

Jun 16, 2009

Just started working with the webview. The issue is performance following rotation. The WebView has to reload the page, which can be a bit tedious.What's the best of of handling an orientation change without reloading the page from source each time?

View 2 Replies View Related

Android :: Orientation Change Handling On Widgets

May 31, 2009

Some of the content in my widget is based on custom drawing routines. is there any event i can listen for so i redraw and update this custom area when the orientation changes? currently my widget looks pretty screwed until the next widget update is requested.

View 3 Replies View Related

Android :: EditText Handling While Orientation Change

Feb 1, 2010

I have EditText in my application. While entering the text i am changing the portrait mode to landscape mode. Not the entered text is resetting. how do i handle this? Like if i change the orientation what ever entered text should be remain as it is.

View 2 Replies View Related

Android :: Handling Orientation Changes That Occur In Another Activity

Jun 3, 2010

I am having an interesting problem and would appreciate any advice. My app uses WebView as its primary view. Using a javascript hook, it can launch the camera so the user can take a picture. The camera is launched using: Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

When the camera starts, it makes sense to use landscape mode, so the user naturally turns the phone on its side. After the user takes a picture, control returns to my launching Activity (actually, my Acitivity gets restarted because it usually gets destroyed to free up memory for the camera on my Moto Droid). When my WebView gets recreated, I restore its state from the Bundle I saved in onSaveInstanceState().

Now everything looks ok, except the phone is still in landscape mode. However, when the user turns the phone upright bringing back into portrait mode, my WebView takes up only half of the screen. Somewhere along the way, the scale of my WebView got lost. This seems like such a minor issue, but it is driving me crazy.

Does anyone have an idea why this might be happening? What is the correct way to preserve the scale of my WebView? I am hesitant to hard code any scale factors because what looks good on my device may not be the same for another.

View 8 Replies View Related

Android :: Android Handling Dynamically Added Views While Orientation Change

Oct 27, 2010

I have a ViewGroup that gets inflated dynamically. I have set Id's to all the inflated views. I am still not able to retain the inflated ViewGroup whenever the orientation is changed. Any particular check that i am missing here ?

View 1 Replies View Related

Android :: Android GridView Reversing After Handling Orientation Change

Jun 19, 2010

My main application screen uses a GridView to display a grid of icons. Each icon has an image, name, and Intent. I have the Activity set to handle orientation changes so I can change the background. The onCreate method sets up the GridView with 3 test icons that don't do anything and a preferences icon which opens a PreferencesActivity:............

View 2 Replies View Related

Android :: Android - Wakelock & Handling Orientation Change

Jan 13, 2010

I'm using Wakelock in my application to prevent the phone from sleeping when the app is visible. The problem comes when there is an orientation change and the system destroys and re-creates the app in landscape mode. If the wakelock timer has expired in the background the system takes the release of wakelock as an opportunity to switch off the screen.

Edit: I should mention that I am setting Wakelock onResume, and releasing onPause - as I understand it, it's necessary to release then to prevent the app from leaking the wakelock. I need wakelock to continue through the orientation change. Below I've outlined a solution to this. Is this the preferred way to handle it, and are there any alternatives?

Create a service which holds wakelock (rather than the activity) and when the activity unbinds the service starts a countdown timer (for say 10 seconds) in which it will release wakelock when the timer expires if the activity does not rebind. If it was a simple orientation change the activity will rebind within that 10 seconds and so maintain wakelock, if it doesn't, wakelock will be released.

View 1 Replies View Related

Android : Click Handling From Multiple Buttons On A Screen?

Aug 8, 2010

The following code is from http://developer.android.com/guide/topics/ui/ui-events.html and shows how to handle a click on a button (called corky, I think) If I had several (say 10) buttons on a form, each launching a different subscreen, would I have to find and repeat the setOnClickListener statement for each button, then put a switch statement in the onClick subroutine, or is there a better way to do it? (I'd rather not resort to naming my buttons Button1, Button2 etc and using a loop). code...

View 2 Replies View Related

Android :: How To Check Screen Orientation While Call On Screen?

Dec 16, 2009

Is it possible to check the screen orientation (I mean whether the screen in landscape or portrait mode) while the outgoing call is going on.If it possible please suggest me how to achieve that.

View 2 Replies View Related

Motorola Milestone :: Manually Rotate Screen Or Keep / Fix Current Screen Orientation

May 29, 2010

is it possible to manually rotate the screen or fix the current screen orientation (with a key/button)? because it really annoys me having taken portrait pictures that cannot be viewed (with the media gallery application) in a portrait fashion on the milestone. this is because it always rotates the portrait picture back to landscape when rotating the milestone from landscape to portrait. right now there is no way of properly viewing portrait pictures on the milestone other than tilting your head (holding the milestone landscape and tilting your head along).this cannot be the way it was intended to be, right? or do I have to get a different viewing software which allows you to choose screen orientation? is there such an app?

View 1 Replies View Related

Android :: Set Screen Orientation Of A Tab

Mar 18, 2009

I would a Tab (in a TabHost) to have a Landscape orientation while the activity with the TabHost is in Portrait orientation, is that possible (if so how)? I tried setting the orientation of the Activity displayed in the tab in the Manifest but it didn't work.

View 7 Replies View Related

Android App And Screen Orientation

Jan 19, 2012

I was wondering if there was any java code that will allow you to make sure each window in your app stays in portrait despite the user flipping the phone to landscape. I already tried inserting android:screenOrientation="portrait" into both my android manifest and into every single XML file I had but unfortunately only some stayed in portrait and others still flipped to landscape.

View 3 Replies View Related

Android :: Screen Orientation Change

Oct 8, 2009

I notice when using the emulator that when the screen is flipped, I get a following logcat message:

INFO/WindowManager(589): onOrientationChanged, rotation changed to 1

How can I catch this in the code? I want to know whenever the orientation changes. I assume I have to set a listener, but I can't find an example anywhere.

View 6 Replies View Related

Android :: Keep Screen On And Change Orientation

Feb 11, 2009

I am making an Android app which is currently coming along nicely - I've hit upon a couple of stumbling blocks.

1) How do I stop the screen from going dim/off and the phone locking while the application is running?

2) Can I force the phone to enter landscape mode on running my application?

View 2 Replies View Related

Android :: How To Get Current Screen Orientation

Jul 2, 2010

I simply want to do code...

The problem is - getRequestedOrientation always returns -1. Any suggestions?

View 2 Replies View Related

Android :: Live Wallpaper Screen Orientation

Sep 23, 2010

I have a series of live wallpapers out and one major sticking point I have with a certain set is that when devices switch to Landscape, the wallpaper, which in most cases is an image designed to fit the screen in portrait mode, appears off center. What is the conventional way to detect the shift from portrait to landscape?

View 2 Replies View Related

Android :: Threads And Screen Orientation Change

Aug 30, 2009

In the following sequence of events:

1. Start a new thread (as a result of a button click - or similar).

2. User changes the screen orientation (causing the Activity that started the thread to be destroyed).

3. Thread finishes, and wants to do some dialog (or any UI) work. However, doing a showDialog, dismissDialog, ... will crash, as the thread it still referring to the old Activity.

This can be solved by updating the data in the thread to refer to the new Activity upon a screen orientation change.

However, couldn't the Android framework just forward any requests from a destroyed activity, to the newly created Activity, saving us developers of handling it ourselves?

View 24 Replies View Related

Android :: On Screen Orientation Changes Activity Restarted

Aug 16, 2010

I know on screen orientation changes activity restarted, but suppose i don't want to restart the activity then what should I do? I had tried it by adding in manifest.xml. android:configChanges="keyboardHidden|orientation"

and override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); }

But still activity restarted each time when I change screen orientation.

View 17 Replies View Related

Android :: Fix Orientation Of App On Screen / Control Accelerometer?

Mar 2, 2010

Please tell me how i can stop the change in orientation of application when device rotate. How i can control the accelerometer.

View 5 Replies View Related

Android :: OutOfMemoryError When Changing Screen Orientation

May 8, 2009

I get an OutOfMemoryError every time i change the screen orientation and I am having a hard time finding the mistake...

The Activitie's view consists of an ImageView, two Buttons and a Spinner. I don't have static variables and can't imagine where i could leak a context.

Most of the times, the exception is thrown at setContentView (R.layout.upload); sometimes it goes fine until imgUpload.setImageURI(imageURI);

The images i am displaying are form the G1's camera, so about 500kb and 2048x1536pixels

Here is some code:

CODE:..................

View 3 Replies View Related

Android :: Prevent An App From Going To Home Screen When Orientation Is Changed?

Nov 18, 2010

I snap a photo, and it gets placed onto an ImageView. When the user sees the page where the Image View is, and I turn the phone sideways where the orientation is horizontal, the app immediately returns to the app's main screen.

View 1 Replies View Related

Android :: Way To Force Screen Orientation To Landscape Right As Of Froyo?

Sep 24, 2010

We currently use Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_x) to set (and 'freeze') the orientation of our app. Froyo now supports two landscape modes tho and we'd like to allow our users to orient the app to 'landscape right' ... ie, the orientation obtained by turning a device naturally oriented to Portrait 90 degrees clock wise.

View 3 Replies View Related

Android :: Force Screen Orientation And Destroy Call

Aug 27, 2009

I want my Activity to be always in portrait mode and I do NOT want the onDestroy() method to be called. There are some interesting articles about that at: http://www.androidguys.com/2008/11/24/rotational-forces-part-four/

The solution seems to be: In AndroidManifest.xml:

CODE:...............

I've tried it and it seems to work. Is there any other alternative or is it the correct solution?

View 7 Replies View Related

Android :: Catch Screen Orientation Change In OnPause()?

Apr 23, 2010

Specifically, I need a way of _not_ performing the onPause functionality I've implemented when it occurs because of a change in screen orientation.

View 9 Replies View Related

Android :: Display Image From URL - Sizing And Screen Orientation?

Aug 30, 2010

I am trying to display an image from a URL, which may be larger than the screen dimensions. I have it kind of working, but I would like it to scale to fit the screen, and I also have problems when the screen orientation changes. The image is tiny, and I would like it to scale its width to the screen as well. (In both cases, I would like the image to fill the screen width with scrollbars (if necessary for height).

Here is my ImageView:

CODE:..............

Here is the java code which loads the image: (some error handling code removed for simplicity)

CODE:.........

I have tried different settings for android:scaleType. I'm sorry if this question has been asked before. I've gone through a number of tutorials on the subject, but they don't seem to work for me. Not sure if it has anything to do with the way the image is loaded. (from the web instead of a local resource)

Another issue is that sometimes the image doesn't even load. There are no runtime errors, I just get nothing in the ImageView.

View 1 Replies View Related

Android : Assigning Keyboard Based On Screen Orientation

Nov 5, 2010

Finally I've been waiting for something like this. Swype - portrait; stock - landscape.Assign Keyboards Based on Orientation - Keyboard Manager for Android | xda-developers

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved