Android :: Android Orientation Change Calls OnCreate
Jun 22, 2010
I've made a search screen that has one tab for keywords, filters, and a search button, and three optional tabs for the different types of results (each containing a ListView with an ArrayAdapter). When starting the activity, the developer can optionally pass in the results as an extra Parcelable[] if the search has already been performed. In the onCreate() method I'm creating each of the three tabs for the Parcelable[] passed through.
When I call a search from the button on the filter tab, I clear the tabs and recreate them with the new results, which works perfectly. The problem is that when you rotate the device, it appears that Android's automatic orientation switching support recreates the entire activity, calling onCreate(). This means that my search results are reset to the Parcelable[] passed through when starting the activity. The only solution I've had so far is to call finish() then startActivity() to essentially restart the activity with the new results. I'm sure there must be a much simpler solution and that I've done something extremely noobish.
View 1 Replies
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
Jun 20, 2010
I've been experimenting with orientation change and have seen a strange behavior (at least to my opinion) when I change the orientation from landscape to portrait. To make the explanation more concrete let's consider the following super-simple code:
CODE:...................
I put breakpoints at lines 9 and 15 and start the emulator in debug mode. The application starts and hits the breakpoint at line 9; so far so good. Then I press Ctrl+F11 to change the orientation from portrait to landscape. The debugger stops first at line 15 and then line 9. Everyhting normal so far. I hit once again Ctrl+F11 to change the orientation from landscape to portrait and some mumbo-jumbo starts happening. Here is the sequence of function calls I observe: 1.onDestroy() 2.onCreate() 3.onDestroy() 4.onCreate()
I really fail to understand why the platform needs to make the calls "2.onCreate()" and "3.onDestroy()". Can anyone explain why this is happening? At least I don't find it convenient because I need to implement more logic, because the extra calls "2.onCreate()" and "3.onDestroy()" cause side effects in my case. However, it would be interesting to know why these extra calls are taking place.
View 5 Replies
View Related
Oct 29, 2010
I want to change layout without calling the onCreate method. i also define android:configChanges="orientation|keyboardHidden" in my activity and it is not calling the onCreate method but the layout not adjust appropriately on landscape mode.
my current layout look like as follows.
after change orientation as landscape it look like as follows:
but on landscape i want the following result.
is there any auto adjacent property?
how can i do it?
View 2 Replies
View Related
Jan 4, 2010
With following simple code (on clean, new android project):
CODE:..............................
View 5 Replies
View Related
Dec 14, 2009
I got my hands on Android which is really fun. But at some point I don't seem to understand the concept. I've got a Main class which reads like this:
CODE:....
In the onCreate(...) I set the layout to setContentView(R.layout.main); and add an OnTouchEvent Listener to the sole View in main.xml: myView.setOnTouchListener(new OnTouchListener() {@Override public boolean onTouch(View v, MotionEvent event){...
As you can see I also implemented a SensorEventListener which is used if required. All works fine so far.
But my problem is this (at this point my misunderstanding kicks in): whenever I rotate the device the onCreate(), onStart() etc. methods are called, causing my app to act as if it just started. Furthermore, I feel unable to implement an onSizeChanged(int w, int h, int oldw, int oldh) { ... } Listener.
Can anyone please explain where my error in reasoning is? I am working on a tiny app which is more or less done, except for the just mentioned bug(s). Maybe I got it all wrong but it does what it is supposed to do (i.e. sending touch positions and accelerometer data over the network via UDP).
View 14 Replies
View Related
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
Jul 31, 2010
In my application I notify the user with notifications, if something special happens:
public void triggerNotification(String msg) {
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent contentIntent = new Intent(this, ABC.class);
Notification notification = new Notification(R.drawable.icon, msg, System.currentTimeMillis());
notification.setLatestEventInfo(this, "ABC", msg, PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent, PendingIntent.FLAG_CANCEL_CURRENT));
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notificationCounter, notification);
notificationCounter++;
}
If the user clicks on the Notification, the onCreate() method is called. But I want that a specific method in my app is called, or if the app is not in the foreground, that it is brought back to the foreground. I know there are lots of tutorials that explain how to handle notifications, but I just don't understand them completely and wasn't ever able to implement the things like I'd like to.
View 1 Replies
View Related
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?
View 2 Replies
View Related
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
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
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
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
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
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
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
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
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
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
Nov 6, 2010
I want to know how to change the orientation of my layout inside of eclipse.
View 1 Replies
View Related
Mar 17, 2009
consider the simple layout:
CODE:..................
View 9 Replies
View Related
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
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
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
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
Apr 15, 2010
Well, preventing an orientation change is easy. But what about doing it at run time.
Say, I have an activity which supports orientation change in normal situations. It has say three Edit Texts.
There's also a button, which when clicked would do some processing in a thread while showing a ProgressDialog which is not cancellable.
Ok, so till the user hits the Button, I want the activity to be able to adapt the orientation changes. I have two layouts files for each orientation with different layout schemes.
What I want is this. Once the user clicks on the button, and the ProgressDialog is showing, I don't want the activity now to be re- created again when the orientation changes. So, before showing the ProgressDialog, is there any way to tell the Activity not to handle Orientation change?
Also, once the process is complete, and the ProgressDialog is removed, I want the Activity again to be able to handle orientation changes.
View 6 Replies
View Related
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
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
Jun 17, 2009
Is the view aware of the orientation change in order to return updated size after a change in orientation? I'm handling the orientation myself (android:configChanges="orientation|keyboardHidden"). Does it means that I have to take into account the orientation state when querying for view.getHeight()? The view returns the same value as before the orientation change. It this the normal behavior or I should "notify" somehow the view to "refresh" its size.
View 2 Replies
View Related
Oct 12, 2010
I was looking at the way Android handles orientation change for my application (I discovered that it restarts the mainactivity on orientation change :| ). I've seen that you can ovveride the method protected void onSaveInstanceState(Bundle outState)to save stuff, then have the in onStart. The problem is that I've my view with custom objects and a listview using a custom adapter... Everything is in a ArrayList of these objects, but I've noticed that you can't put arbitrary objects in the bundle! So how do I save the state?
View 2 Replies
View Related