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?

Android :: Handling Orientation Changes in AppWidgets


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 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 ?

View 1 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 :: 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 :: 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 :: Potential - Bug In The Implementation Of AppWidgets

Nov 10, 2009

We have discovered a potential bug in the implementation of AppWidgets. Here is a simple reproducer.

Attached is the code for an application containing a TestActivity and a TestWidget. TestActivity extends MapActivity and TestWidget is a simple widget provider which updates a TextView every 2 seconds. Now if the TestActivity is launched with no instance of TestWidget running, it works just fine. But if the TestActivity is launched after placing the TestWidget on the home, it results in ClassNotFoundException. Here is what we get:

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

So it seems we have an inconsistency in the way the class loader works for the same apk.

WORKS - Launch the application by itself, without invoking the Widget. DOES NOT WORK - Create a Widget on the Home screen and then launch the application from the launcher.

The source code for this application (http://www.yousendit.com/ download/TzY3ZGVhZy96NE4zZUE9PQ) has been attached. Hope someone from the Android team can shed light on this behavior.

This error is seen on the 1.5r3 SDK. Not sure if this has been addressed in 1.6 and 2.0 SDKs..

View 2 Replies View Related

Android :: Debugger Not Working For AppWidgets?

May 8, 2009

I'm trying to make an AppWidget, and for some reason the Eclipse debugger doesn't suspend on any of the breakpoints I set (but I know the code is executed because I see it working on the emulator). I don't have this problem with other 'regular' apps (non AppWidgets). Is this a known limitation, or is it just a problem on my installation?

View 4 Replies View Related

Android :: AppWidgets Restricted To Particular Sizes?

Sep 17, 2010

I'm making an Android AppWidget to sit on the home screen.

The user's home screen space is precious, so I want the widget to be small. The ideal size would be 2x1 cells.

Some documentation suggests you can have any size you like?
But the AppWidget graphical design guidelines imply that only standard sizes are supported: 4x1, 3x3, 2x2.

Does that refer to the available PhotoShop templates or is it a limitation of Android itself?

I'm finding that a 2x1 widget works on my actual device (HTC Wildfire) but expands to 2x2 on the emulator.

HTC have their own special implementation of the home screen, so maybe my widget will only work at 2x1 on HTC devices?

Is there any way to create a 2x1 widget, or should I use a standard size?

My widget was adapted from the Simple Wiktionary sample.

The manifest has android:minWidth="146dip" and android:minHeight="72dip".
There's a RelativeLayout with android:layout_width="fill_parent" and android:layout_height="wrap_content"

I'm just starting with Android, so apologies in advance if this is a silly question. :)

View 1 Replies View Related

Android :: Create Customized Views For AppWidgets?

Jan 22, 2010

There is a given set of predefinied Views that can be used in layouts for AppWidgets. How can a customized View added to this list?

The minimum requirement is that the class is annotated with RemoteView. What else is necessary to be acceptable as view in the layout.xml?

View 2 Replies View Related

Android :: Programmatically Create / Destroy AppWidgets?

Mar 5, 2010

Is it possible to programmatically create and/or destroy AppWidgets?

View 7 Replies View Related

Android :: AppWidgets - Reusing RemoteViews Instance Leaks Memory?

May 21, 2009

I'm writing a widget. Currently, I'm have a simple ImageView, and calling RemoteViews.setImageViewBitmap(). I'm using a service to do the updates.

I thought it might be a good idea to reuse an existing RemoteViews instance, so I'm only querying it the first time around, and subsequently simply call setImageViewBitmap() with the new image.

This works well initially, but after some time I first start getting "!!! FAILED BINDER TRANSACTION !!!" errors, and later, an OutOfMemory exception.

Simply creating a new RemoveViews instance every time works flawlessy on the other hand. I'm just curios why that would be, any ideas?

View 2 Replies View Related

Android :: Make A Flexible AppWidgets In Droid According To Screen Size?

Oct 6, 2010

Can anyone tell me how to make a flexible AppWidgets in android according to the screen size.
I want to make a full screen widget, but when it change screen size, i want to make it flexible.

View 1 Replies View Related

Android :: Orientation Change - Dialog Above Activity With Fixed Orientation

May 14, 2009

I have created an activity for my game which handles all orientation changes by itself and has a fixed "portrait" layout. Actually it uses the accelerometer and is rendered using 2D canvas methods. If the level has been completed I show up a highscore dialog in which the user can enter his name. The dialog is floating above the underlying level screen which gets blurred out nicely. This generally works.

Problem is that the dialog does not get rotated if the orientation of the phone changes. So even if the keyboard is exposed the dialog is shown in portrait mode instead of landscape. I have tried to use an activity with dialog theme instead but the behavior didn't change. After several tries it seems that I have found the reason for this: Once there's an activity with fixed orientation in the activity stack then all subsequent activities keep this orientation, too. They will not react on orientation changes anymore (e.g. if the keyboard gets exposed).

After upgrading to 1.5 SDK the described behavior changed a little bit. Now at subactivities indead react on orientation changes like expected. However, the need to have an opaque background! That means that neither dialogs nor activities with dialog theme will work. Those will stick with the orientation of the underlaying activity. So my workaround is to first start a sub-activity with an opaque black background. This activity then shows my highscore dialog on top. It looks quite okay but I wonder if there's a better solution? Is it possible to show a dialog above a fixed portrait or landscape activity which automatically adapts to orientation changes?

View 3 Replies View Related

Android :: Can Force A Specific Layout Orientation - But Have An Opposite Keyboard Orientation Android

Aug 19, 2010

I understand how to force a specific orientation per activity in the android manifest. I would like to know if it is possible to allow the keyboard to change orientation even though the activity(the layout really) must remain unchanged.

View 1 Replies View Related

Android :: Using Orientation Sensor To Get 360° Orientation

Jul 17, 2009

I have a problem with working with the ORIENTATION values of the SensorManager. I would like to have some kind of 360°-value which directly shows me if the phone is in normal portrait (0°), landscape, portrait turned around (180°) or anything in between. So I could have, for example, an arrow that points to the floor (like gravity would do with a plummet) all the time, no matter how I tilt (sidewards) the phone. I thought this would be easy, but I'm pretty confused at the moment.

First of all, the X value of the orientation-array seems to correspondent with how I turn the phone, BUT: if it's completely uprightly standing, this value is about 60° ... why not 0° (or 90°, 180°, 270°), as I would expect?

Second: The value resets if I turn the phone and Android automatically changes screen orientation. So both in Portrait and in Landscape mode it will be sth. like 60° when the phone is in a 0° angel in real world. I set "android:screenOrientation" to "landscape" but this doesn't help anything :/

I want the app NOT to change orientation when I turn the phone, but I want it to get a continuous orientation value when I tilt the phone.

View 4 Replies View Related

Android :: Best Way To Handling XML

Sep 2, 2010

Android device is much slower and have much lower memory compare to PC/server, So what is the best way to handling XML in Android? And I have a set of very complex xml needed to parse. both SAX or DOM will cause too much code. Anybody have good suggestion? I want to make it clean and fast.

View 4 Replies View Related

Android :: Exception Handling ?

Aug 9, 2010

I read somewhere not to exception handle when developing in Android, is that true?

If one does need to exception handle are there any logging tools for 2.1 and above?

If shouldn't exception handle, why is it not recommended to at least use the below?
try {body-code} catch (exception-classname variable-name) {handler-code}

View 3 Replies View Related

Android :: Try/except Handling For PostMethod?

Apr 6, 2010

I'm using a PostMethod, and wondering what try/except handling I should use.

The exception handling here seems to work okay in most scenarios, but is there anything I might be missing? In particular, I'm wondering whether this handles the network connection going down midway through the upload.

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

View 2 Replies View Related

Android :: Handcent Handling MMS?

Jan 1, 2010

I've been wondering if Handcent is supposed to move all my pictures to the top of each thread? And is there anyway to save the pictures with Handcent?

View 2 Replies View Related

Android :: Handling Of Multitouch?

Sep 22, 2010

I'm trying to do is draw circles around two points that are being touched, and as the fingers drag along on the screen, have these circles follow each finger.

However, I'm getting some weird behavior that I can't figure out. So when I place two fingers on the screen I get my circles no problem. When I drag around with the two fingers everything works like I want it. However, if I lift the first finger, everything stops redrawing, and the second finger that is still on the screen stops being tracked. If I place the first finger back on, everything behaves good again. I figure I must be handling the two fingers poorly.

Also, if I have two fingers on the screen, and I lift and touch the second finger, everything behaves well. It's only in the case where I have two fingers and I lift the first one do I see a problem.

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

View 1 Replies View Related

Android :: Best Way Of Handling UI Code From Thread?

Feb 7, 2010

I know how to use handlers to update UI elements such as progress bars toasts etc. The problem I am having is when the context goes away such as the user pressing the back button or the Activity finishing for some reason. This causes my application to crash often. I tried using
getApplicationContext()
(Thinking that this would be available throughout my entire application) but this did not work, ever - instead my application crashed! I put try catch blocks around all UI update code, this works but is it necessary? What is the bast way to handle this?

View 1 Replies View Related

Android :: Market Error Handling

Jun 16, 2010

I have some required try/catch statements in my application that in my testing never get called. I have sent them up with:

Log.e("messaage", e.toString());

For my debugging and now that I'm ready to release I am not sure if I should take that out or not. I see in android market you can get error/crash reports and while I do not expect my app to catch any errors, I would like to know if that happens and wondering if I need specific syntax for that. My question is what should I do in the catch statement for these errors? I'm already handling the error from a user standpoint...

View 1 Replies View Related

Android :: Long Key Press Handling In 1.5

Mar 23, 2010

I want to handle key press and long key press for the key code KEYCODE_CALL(dial button). can any one suggest me how this in android 1.5(API level 3).

View 2 Replies View Related

Android :: Handling Status Bar Notification

Mar 8, 2010

in my app a background service starts and from that service i want to set Status bar notification, that the service has Started following is the Notification is displayed in Status bar But whin i click on that MyClass.class is not fired.And in log cat it shows
"Input Manager Service Window already focused ignoring focusing ...." Code...

View 2 Replies View Related







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