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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Feb 22, 2010
I have a basic app with text inputs, a spinner input, and a second spinner input whose array depends on a setting changed in the Options menu. Currently, when I press Home or press Return while in my app, I either return to the desktop or cycle back through old inputs i put in recently. How can I prevent my app from opening multiple instances of itself so that there is only one instance running at any given time, and then how can I save the data entered into inputs, and the settings chosen in my option menu? I'm a bit new to Java, so I apologize if this is a simple problem.
View 1 Replies
View Related
Apr 24, 2009
At the moment I am trying to update my application to Android 1.5. In Android 1.1 I was able to detect the BT state with catching the following broadcasts: Code...
View 8 Replies
View Related
Jan 11, 2010
I understand how to save an application's state by using SharedPreferences, onSavedInstanceState() & onRestoreInstanceState(), etc as outlined in a similar post ( http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state ), but how do I save the last activity?
To be more specific, my application starts up and goes to a login screen. Once a user logs in and navigates through several activities, lets say he or she leaves the app using the home button or in some other way. Next time the user starts the app, it will go back to the login screen and do a login again. Instead, I want the app to start up and go to the last activity that was on top of the stack when the user left the app in the previous session.
How is the last activity saved so that it can be restored on app startup?
View 3 Replies
View Related
Jul 5, 2010
Which of the following is/are appropriate for saving the state of an Android application?
a. Activity.onFreeze()
b. Activity.onPause()
c. Activity.onStop()
d. Activity.onDestroy()
e. Activity.onFinish()
View 2 Replies
View Related
Aug 11, 2010
Is android have application state, like background or front?I have a situation when need to update same data if app is coming to front.onRestart or onStart is not good idea, because this method fire when we come from another activity.
View 23 Replies
View Related
Dec 6, 2009
Anyone know what providing an application access to "Phone calls: read phone state and identity" actually does?
View 5 Replies
View Related
Oct 28, 2010
I have a Service which tracks the location of the user. Currently, the Service boots when the application starts and stops when the application terminates. Unfortunately, if users keep the application in the background, the Service never stops and drains battery.
I would like the Service to stop when my application is not in the foreground. I was hoping the Application class would let me Override onPause and onResume handlers, but it does not have them.
View 1 Replies
View Related
Nov 17, 2009
i've registered a PhoneStateListener in BOOT_COMPLETED receiver by using following call: tm.listen(new TestCallStateListener(), PhoneStateListener. LISTEN_ CALL _STATE); If the application crashes then system automatically unregisters the PhoneStateListener. Is there any mechanism of checking if particular PhoneStateLister is registered or not? Actually i'm thinking of starting a repeating service by AlarmManager which will check if PhoneStateListener is registered or not . And if it's not registered then service will register it again. Just a backup if application crashes. Is this a good approach or there is some better mechanism to make sure that PhoneStateListener is always registered even if application crashes ?
View 2 Replies
View Related
Dec 22, 2009
I just read from internet to maintain the state of my application by overriding the onKeyDown function as given below. And set the launch mode of my activity as singleInstance. And it is working perfectly. Just want to know if it is correct approach. And how it is different from onSaveInstanceState.
View 3 Replies
View Related