Android :: How To Save State During Orientation Change?

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?

Android :: How to save state during orientation change?


Android :: Save My Custom View's State After Orientation Change?

Oct 20, 2009

I have a custom View, what is the proper way of saving / restoring it's state after orientation change. I know I should implement onSaveStateInstatnce() and onRestoreInstanceState() methods, but how exactly (with which argumets) and when I should call them?

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 :: Maintain Scrolling State While Orientation Change In Android

Oct 5, 2010

I have created one custom view that contains the horizontalscrollview. Now when i changes the orientation its scroll state change to 0 every time. I got the previous scroll state by using onSaveInstanceState(Bundle savedInstanceState) and onRestoreInstanceState(Bundle savedInstanceState) . in onRestoreInstanceState i am using following method to get reposition the scroll, hoz_scroll.scrollTo(hoz_x_pos, hoz_scroll.getScrollY());

View 2 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 :: Maintaining The State When Changing The Orientation

May 13, 2010

I am having an application showing ListItems and Dialog boxes in it.. I want that when i change the orientation from Portrait to landscape mode, i need to maintain the state of the application .. I have seperate XMLs for landscape and portrait mode..

View 11 Replies View Related

Android :: Prevent Custom Views From Losing State Across Screen Orientation Changes

Aug 22, 2010

I've successfully implemented onRetainNonConfigurationInstance() for my main activity to save and restore certain critical components across screen orientation changes.

But it seems, my custom views are being re-created from scratch when the orientation changes. This makes sense, although in my case it's inconvenient because the custom view in question is an X/Y plot and the plotted points are stored in the custom view.

Is there a crafty way to implement something similar to onRetainNonConfigurationInstance() for a custom view, or do I need to just implement methods in the custom view which allow me to get and set its "state"?

View 1 Replies View Related

Android :: Dev - Save State

Sep 1, 2010

can someone helpme out with how to save state of the app when the screen orientation is changed i read the development guide at http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

But i dont know how to define the method collectMyLoadedData();

View 2 Replies View Related

Android :: How To Save App State In Phone?

Aug 30, 2010

I am writing an app where I get all the data from the rest call and display all the data in a custom component list(based on Linear Layout) which is added to a LinearLayout. I write this code in onCreate of the activity. The problem is when I switch activity using startActivity, and come back to the calling activity (using startActivity) then onCreate is called again. I see onPause, onStop called when I call other activity. Is there any way that I can save the application's state?

View 1 Replies View Related

Android :: Save State In My Application

Jul 16, 2010

I am developing an android application in which,the first activity is that for Login. After successful authentication, user can see an activity with 4 Tabs. My problem is that when user taps on the home button,the application should terminate and when the user again starts my application, he should be able to see the Login screen again and after successful Login, user should be able to see the tab on which he was working before application terminated(i.e., save state for all the tabs).

View 3 Replies View Related

Android :: Save .app.Application State?

Aug 9, 2010

I've encountered a problem wile using my own subclass of android.app.Application. I have numerous activities in my application and I'm running a custom ROM which consumes quite a lot of memory. What happens is when I launch a third party activity (Camera) my Application is killed. My Application subclass stores vital data for the whole app so it can't work without it. android.app.Application doesn't have any methods for saving or restoring application state. Activity does have them but they are not suitable.

How to perform save/restore state on Application subclass?

UPDATE I've managed to do so by filling a Bundle obtained from onSaveInstanceState and restoring values in onCreate. But is there any better way?

View 1 Replies View Related

Android :: Save State Between Orientations?

Sep 4, 2010

In a previous question I asked how I could display two different layouts for portrait and landscape orientations:

Problem switching to landscape orientation

Now I would like to know how I can save the state of my application before it goes into another orientation? I seem to lose this data any time orientation changes.

View 1 Replies View Related

Android :: Save Instance State For Dialogs?

Sep 24, 2009

I wonder what is the right way to implement this? Could anybody advice whether my solution is correct?

So:
Activity is created
User clicks on button and dialog is launched (Dialog, not dialog styled activity)
User opens keyboard
we have onSaveInstanceState called where we save that our dialog was opened and all respective dialog input
we have onRestoreInstanceState and here we check whether dialog was shown, recreate the dialog with respective input.

Is it the right approach? or there is smth. that is done by Android and I am doing some redundant actions.

View 2 Replies View Related

Android :: How To Save State Of An Activity On An ActivityUnitTestCase

Jan 22, 2009

In an ActivityUnitTestCase I'm trying to do:

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

But on the save state call I get this trace:

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

Going through the ApplicationContext source code I've found this (http://tinyurl.com/d8qsyc):

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

It seems the problem is that the activity token is not set. But here I'm puzzled, I don't know where to go next. Any ideas on how to fix it or workaround it are appreciated. I want to test that my application is saving its state correctly.

View 3 Replies View Related

Android :: Correct Way To Save State Of An Activity?

Jul 1, 2010

I have an Activity, which contains a bunch of check boxes and a submit button.

When the submit button is clicked, the activity will exit (finish() will be called). Before the activity exits, I want to save the states of the check boxes in the activity, so when the activity starts again, the check boxes can stay in their previous states. What's the correct way to save these states? Should I use SharedPreference.

View 1 Replies View Related

Android :: Save Instance State Of My Application?

Jan 11, 2010

As a follow on from my question on sharing state between Activities, how can I save the instance state of my Application? Since Application does not extend Activity, there is no onSaveInstanceState method to override.

NB: In advance, this is not a duplicate. Despite its name, How do I save an Android application's state? relates to Activity state

View 1 Replies View Related

Android :: Save - Complex - Application State To Bundle

Apr 30, 2010

This is a bit complicated to explain (and my first post), so bear with me please: I am currently trying to figure out the best way of saving my application's state in a bundle on the onSaveInstanceState event (working on a game). My application's state is based on a "world" class which contains various objects. Among these objects there is a creature object which contains bitmaps (Bitmap object)(allowing me to draw the various sprites of the creature when it's walking with more flexibility and accessibility).

Bit of creature constructor Java:

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

After looking around for a few hours I found that serializing the world object (and all its sub-objects) was an acceptable way of saving it in the bundle. Unfortunately it appears that we can't serialize bitmaps and considering they're a part of my "creature" I can't seem to see a workaround.

Here come my questions: 1- Am I doing something fundamentally wrong? (not supposed to save bitmaps in objects? supposed to handle bitmaps in a separate class which I don't pass on the bundle and reload my bitmaps when restoring the application? ...) 2- Is there another way of passing my "world" object into my bundle (would using Parcelable work?)

View 5 Replies View Related

Android :: Phone Won't Save Current State Of An Activity / Way To Do

Nov 17, 2010

I am trying to save some values in the onSaveInstanceState(Bundle) method of my activty by following the example here: How do I save an Android application's state?

But it doesnt seem to load it from the Oncreate(). the bundle object is always null but whenever i call another activity, it does indeed go into the onSaveInstanceState method to save my values.

Now i read that question i just posted and someone noted how they could not get it to work in an emulator? unfortunately that is all im working on. On an emulator and cant test the app on the device as i have no device available to me right now And the web services i am interacting with are in a local VM on my work machine that cannot be accesses remotely at the moment.

My question is, is it true that saved bundles dont work on emulators? I also noticed how when i do dismiss or bring up a new activity , the activity calles onPause and then onStop. when i bring back the same activty, it goes straight to onCreate?

now according to the docs here http://developer.android.com/guide/topics/fundamentals.html#actlife That is correct in terms of what the lifecycle diagram shows but if you read below that diagram on the onStop() section it says the next step it goes into is either onRestart() or onDestroy()? no mention of onCreate? Type on the docs?

Anyways here is my onSaveInstanceState() and onCreate() both in the same activity: code...

View 1 Replies View Related

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?

View 2 Replies View Related

Android :: How To Save An Instance Of A Custom Class In On SaveInstance State?

Jul 3, 2010

I created an instance of a custom class RestaurantList to hold my data (a list of restaurant data received from a web service as json data).How can I save it in onSaveInstanceState? Code...

View 1 Replies View Related

Android :: Save State Of Checked Item In ListView Having Checkbox

Sep 29, 2010

I'm new to android, please help me how to save the state of checkbox,

i.e.

I've ListView with checkbox, three textview and again checkbox. I wish to save the checked state of item(s),

how to save the state of checkbox.

View 5 Replies View Related

Android :: Save Current State Of Canvas As An Image In Droid?

Nov 16, 2010

I'm developing an application which allows user to edit an image and save that edited image as new image on sd card I want to get the current state of the canvas object.

View 2 Replies View Related

Android :: Best Way To Save Large Number Of Checkboxes State In Droid?

Sep 11, 2010

I have some 34 checkboxes on one Activity which i have to mark and unmark. and I want to save the status of the each checkbox.

I want this persistently. So should i have a sqlite table or preferences ?

If sqlite table is recommended, then what should be the ideal table structure design?

View 1 Replies View Related

Android :: Singleton Objects To Save State Or Share Data Between Activities?

Nov 24, 2010

It would be nice if StackOverflow had a section where we could post tutorials like mine so that I can answer literally hundreds of questions that have been asked here with a single blow. See... every day I read questions about how to pass complex objects between activities, how to save state so that your app can resume after orientation change, how to update listviews when the data changes, etc, etc. Here is the second part of a tutorial series I posted on my blog... I hope that you actually read it... because I haven't seen any examples like it anywhere... and it has changed how I think about developing for Android across the board. The question is... is there a downside or negative affect of developing like this?

Beyond Smart Lists - How Observable Singletons change the game. Please read through both of these tutorials carefully... I will answer any questions about it here that I can... I really want to know what you think about this and if it might solve issues for you. NOTE TO MODERATORS: there are no advertisements of any kind on my blog.. so don't just close this because you think I am spamming somehow... I am not going to duplicate my post here.

View 1 Replies View Related

Android :: Droid Save Checkbox State In ListView With Cursor Adapter

Mar 9, 2010

I cant find a way to save the checkbox state when using a Cursor adapter. Everything else works fine but if i click on a checkbox it is repeated when it is recycled. Ive seen examples using array adapters but because of my lack of experience im finding it hard to translate it into using a cursor adapter. Could someone give me an example of how to go about it.code...

View 3 Replies View Related

Android :: Save State Of Droid Application When Back Button Is Pressed?

Sep 20, 2010

I have noticed while working in the emulator that whenever i get out of my app via any method other than pressing the back button, my toggle button (if pressed) will have its state saved and return to that state when i return to the app. im guessing its because its value gets saved in a bundle and reloaded when i return. when i leave the app via the back button, this does not happen and the toggle is always off when i return. is there any way to get the value of the toggle back if the user leaves via the back button, without having to save the value in a db table? alternatively, if my apps notification is in the status bar, i can be confident that the toggle should always be selected, so if there is no way to save the state, is there a way to find out if my apps notification is currently being displayed? then it would be easy to just set the toggle each time via a quick check of the status bar.

View 1 Replies View Related

Android :: Robust + Easy Way To Save / Restore Droid App Instance State?

Feb 19, 2010

In Android, you need to implement the following Activity methods so your application can be restored to its previous state if the OS decides to destroy then recreate your activity:

public void onSaveInstanceState(Bundle savedInstanceState)
public void onRestoreInstanceState(Bundle savedInstanceState)

The examples I've seen of implementing these methods is to use put/getBoolean, put/getInt etc. on the Bundle object (i.e. primitive objects only) to save the application state. This seems hugely error prone way to save your state for a start and I cannot see how this scales to storing complex objects without writing lots of code.

What options do I have for storing/restoring state in a robust and easy to implement fashion?

In case it's important, my application (a game) needs to store about 50 objects, which each store maybe 5 float variables and some store references to other objects. I don't particularly want to have to write save/restore methods for every class and subclass (maybe about 15 of these) I use. It would be ideal if I could just stick all my state relevant objects in an object called "state" and then just call save/load on "state" to handle everything.

Is using Java serialization an option? I've heard it's very slow, but is that a problem for save/restoring? Could I just write my data to the SD card? To a database?

View 1 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 :: Save And Restore A ButtonText When Screen Orientation Is Switched

Nov 7, 2010

As usual in android, each time the screen is flipped to portrait/landscape mode an Activity runs through life-cycle from onSaveInstanceState to onDestroy and then is recreated.In my Activity there's a ButtonText which can be changed by the user. It's reseted to the initial state, but I have to save the last state somehow. How can I achieve that, will I have to override onSaveInstanceState? Can someone show an example?

View 1 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







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