Android :: Change Intent Bundle Data Before Activity Recreated After Orientation Change

Jul 30, 2009

I have a notification that starts my activity and passes a messages using the intent's putExtra() function. The message is then displayed to the user in the activity's onCreate function. When the application is restarted due to a orientation change, the message is shown again as it is still in the intent's bundled data.
How can I remove the extra data?

I tried the following:

Bundle bundle = getIntent().getExtras();
if (bundle.getBoolean("showMessage")) {
// ... show message that is in bundle.getString("message")
// remove message
bundle.remove("showMessage");
}

But the message will still be shown after the orientation changed, seems like the intent used is not the one I changed, but the original one. The only workaround I found is to save the showMessage additionally in onSaveInstanceState(). Is there another way? Or is this the way to go?

Android :: Change intent bundle data before activity recreated after orientation change


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 :: Orientation Change Crash In Tab Activity With List Activity

Jan 21, 2010

When views with different type have same id and screen orientation changes,

either java.lang.ClassCastException: android.view.AbsSavedState$1 or java.lang.IllegalArgumentException: Wrong state class -- expecting View State will occur. (depends on the view's order)

Because View.dispatchRestoreInstanceState() checks id only.

You may wonder why anyone would make views with different type to have same id.

But it can happen when you use tab activity.

Imagine you have tab activity with two children activity.

Tab1 is ListActivity and Tab2 is ExpandableListActivity.

Both activity have id of "@android:id/list" but the type of view is different.

This means we cannot use ListActivity & ExpandableListActivit at the same in one tab activity.

View 4 Replies View Related

Android :: Maintaining State Of Activity On Orientation Change

May 6, 2010

I m currently working on landscape mode for android app in which i want to know how to maintain the state of the activity and views displayed on orientation change i.e from portrait mode to landscape mode ?

View 3 Replies View Related

Android :: Activity Being Killed - OnDestroy - On Orientation Change

Apr 5, 2010

I am working on a MVC implementation for Android (to be subsequently hosted on SF and/or GC).

It works like this:

Activity (View) <=> Application (Controller) <=> Data (Model) <=> Persistence (DB/Network etc)

The scenario is:

1. Activity launch (main/launcher)

2. Notifies Application about performing a data transaction

3. Upon receipt of data response, controller devices which Activity to launch (or update existing)

4. Application has overridden the method onConfigurationChange

Problem: When the orientation is changed, the Application is notified about onConfigurationChange but:

a) The "current" activity is Destroyed and recreated -- which is fine to some extent b) The new instance which is created is automatically => onCreate, onPause, onStop, onDestroy.... now that's catastrophic.

View 4 Replies View Related

Android :: Prevent Rotation/change Of Orientation In Certain Tab/activity

Sep 11, 2010

My MainActivity (the one that is started by the android application) is a TabActivity which contains several tabs (which are implemented as activities as well). In a certain tab/activity I want to prevent the change of orientation/rotation when the phone is turned. What is the easiest way to achieve this?

View 2 Replies View Related

Android :: Background Activity For Map Started Again When Orientation Change

Apr 6, 2010

i've developed an android app that's fetches an xml file and displays this data via several markers on the map. This works fine so far. The problem right now is that when i switch the orientation of the phone (portrait->landscape or vice versa) the markers disappear for a small moment, the xml processing is started again and then they reappear. Is there a way to prevent this re-loading of the file? It only takes about 2-3 seconds.

View 2 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 : Want To Reload Data In ListView When Change Orientation

Nov 17, 2010

I have a listview that Display some Categories on it from my server, it works fine but when i change Orientation it Reload it...

What Should i do to Avoid Reload ?

View 1 Replies View Related

Android :: Show AlertDialog On Activity Start - But Not On Screen Orientation Change

Aug 13, 2010

It seems when screen orientation changes, the activity's onCreate() method is called. In my onCreate() method, I have an AlertDialog which pops up when the activity is called. The problem is when I switch the screen sideways, the popup is displayed again. How can I avoid this?

View 1 Replies View Related

Android :: Perserve The Data In Arrayadapter/listview When Change Orientation?

Feb 26, 2010

As above, is it done automatically? My list was empty once the orientation chMYanges? and nope, i need the orientation change.

My adapter

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

My onCreate

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

View 3 Replies View Related

Android :: Unbind Remote Service In OnDestroy Of Activity On Screen Orientation Change

Nov 24, 2010

In onCreate method of Activity, it binds to a remote service and makes use of AIDL intefaces. Is it required to unbind from the remote service when onDestroy is called on screen orientation change.?

If the activity un-bounded from the remote service in onDestroy and if no other contexts are bound to remote service, is remote service likely to get stopped losing the state that it maintains.?

View 1 Replies View Related

Android :: Screen Flip Doesn't Trigger An Orientation Change And Activity Destruction/recreation

Aug 29, 2010

I'm testing an app on a Droid. It's a kind of card matching game. I'd like to keep the cards physically located in the same place on the screen regardless of a screen rotation. For example, I can put my thumb on a card, rotate the phone any way I please and the card stays fixed under my thumb. However, the orientation of the content of the card will change to match the current phone rotation. I handle this by transforming the card grid in onCreate. This works fine for 90 degree rotations, but if I do a fast 180 degree flip from one landscape mode to another the screen simply flips and the Activity is NOT destroyed and recreated.

This seems contrary to the documentation:

http://developer.android.com/reference/android/R.attr.html#configChanges

"public static final int configChanges Since: API Level 1

Specify one or more configuration changes that the activity will handle itself. If not specified, the activity will be restarted if any of these configuration changes happen in the system. Otherwise, the activity will remain running and its Activity.onConfigurationChanged method called with the new configuration. "

I am NOT specifying any configChanges in my AndroidManifest.xml file, so it seems that the activity SHOULD be destroyed and recreated. Why isn't it? Is there some way I specify that it should be destroy/ recreated?

View 7 Replies View Related

Android :: Change Widget Dimensions On Orientation Change

Jul 22, 2010

I have a widget which has say, a dimension of 294*72(portrait). But when the orientation is changed, I need to change this dimension of the widget to another dimension which would look good on the landscape orientation.

View 4 Replies View Related

Android :: Change Background After Orientation Change

Jun 8, 2010

I have an image set as my background and when it is vertical, the image looks fine. However, when the orentation is changed, the image get streched out. If there a way that I can change the image based on the orentation of the device?

View 4 Replies View Related

Android :: Does OnActivityResult Get Called When An Activity Is Recreated

Sep 30, 2009

I have a flow A->B->C->D where A desires some information that is obtained by D. B, C, and D propagate the data back through the flow using setResult(RESULT_OK, data) and finish(). All intents in A, B, and C are started with startActivityForResult. However, if B is reclaimed by Android and forced to call onCreate again after C finishes onActivityResult in B is never called and the data never makes it back to A. Is there a way I can be sure that onActivityResult will be called?

View 5 Replies View Related

Android :: Change Orientation Of AlertDialog

Mar 25, 2009

I am building a AlertDialog in java code, so by default it is portrait but I want to show it in landscape orientation. How to do it in Java code?

View 2 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 :: Dialogs On A Change Orientation

Mar 5, 2010

I'm doing an APP that shows some dialogs. Those dialogs are Alert dialogs, and when they are being showed if I change the orientation of the mobile I lost them...they are not being kept on the screen.

View 13 Replies View Related

Android :: Views - Orientation Change

Oct 1, 2009

Do Views know changes in orientation? In my case, I create popups from TextView and need to know when the orientation changes(porttrait<-- >landscape). I cannot depend on activity's onOrientationChange.

View 2 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 :: Possible Leak In Orientation Change

Jul 1, 2009

My app *sometimes* when orientation change, leaks Activities (getInstanceCount() increases from time to time) and i cannot figure out where references to my Activity or rather Context are kept - tried to use jhat but it couldn't help me much.

what is strange: it doesn't always happen on orientation change, so its even harder to fix.

btw when doing normal app life cycle - start, do something, exit - everything is ok - getInstanceCount() always returns 1.

View 5 Replies View Related

Android :: OnCreate And Orientation Change

Apr 28, 2010

I have an activity that checks stuffs online when it's created (is the GPS on and if not it asks if the user wants to turn it on).

The problem I'm having is that it is also doing it everytime I change the orientation of the screen.

I've read some comments on onConfigurationChanged() but is there a better way to be sure I'm checking the GPS only when the activity is first created?

View 4 Replies View Related

Android :: Dialog Is Leaked On Orientation Change

Jun 23, 2010

built a simple app that displays an alertDialog with two buttons.The problem is it's not getting dismissed when i change orientation. After change i get a leak warning on debugger and the dialog appears twice(pressing back hides the first dialog, only a second back dismisses it completely).

View 7 Replies View Related

Android :: Change Eclipse Layout Orientation

Nov 6, 2010

I want to know how to change the orientation of my layout inside of eclipse but when I click the "layout" button it still shows it as a vertical layout.

View 4 Replies View Related

Android :: How To Change Eclipse Layout Orientation?

Nov 6, 2010

I want to know how to change the orientation of my layout inside of eclipse.

View 1 Replies View Related

Android :: Orientation Change Crashes When Ids Not Unique

Mar 17, 2009

consider the simple layout:

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

View 9 Replies View Related

Android :: AppWidget Update On Orientation Change

Dec 29, 2009

I am developing a photo frame widget, all works except on an orientation change to landscape mode my appwidget doesn't display correctly as I have it set to portrait dimensions and it is too large for the display. I would like to run some code to resize the image so that everything displays correctly and it uses all the space that I allot. What is the correct way to do this? I can think of 2 methods however both seem inefficient. The first would be to register a broadcast reciever to take orientation changes, however I don't want to redo my appwidget everytime the phone is turned on its side as the majority of the time the homescreen is not showing when the orientation is changed (ie other apps are used, and I don't need my code running in the background). I only need it to run when the home screen is shown. The second would be to setup a service to manage my appwidget but that also seems inefficient to be always running in the background.

View 10 Replies View Related

Android :: Orientation Change Runtime Option

Apr 24, 2009

Is it possible to have a user choose how an app should respond to orientation changes? I have it set to android:screenOrientation="sensor" in the manifest but I would like users to be able to turn this on and off or set landscape or portrait orientation permanently.

View 5 Replies View Related

Android :: Application Restarts On Orientation Change

Nov 2, 2010

When I change orientation application restarts and I lost my current data.. I am using activity group which contain lots of activities when i change orientation application restarts from main activity. is it possible to avoid this application restart on orientation change?

View 4 Replies View Related







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