Android :: Prevent Activity From Saving State When User Selects Back Button
May 2, 2010
I have an Activity with a list that is bound to a ListAdapter reading data into a ArrayList from a database. All is well when the data is first loaded. While the Activity is open and the list is being displayed it is possible and likely that the data in the database will be updated by a service but the list does not reflect the changes because the ArrayList does not know about the changes. If the Activity is no longer in the foreground as would be the case if the user goes to the home screen and then is brought back to the foreground I would like for the Activity to not display what it did prior but rather reload the data using the ListAdapter the view is bound to. I think something needs to call finish() but I am not sure what.
I am having an issue related to home key . when i press home key all current activity gets hidden. but when i press the executable it again starts from the fisrt screen . I have overidden all methods nsaveInstaceState opPause onStop onResume
but there are still issues what is the right way to handle those conditions. When i am pressing home button i am storing the widgets state in database and when i again click the exectable i am checking the database state and starting the new Intent as saved when user presses the home button .Is it the right way to do that as i am facing the problem when user does the same and again presses the back button , there is already on intent available in stack of activity .
Whenever I press the home button when Im in the root task of my application and when I click on the icon of my app again the state of my task (activity) is retained, but when i press the back button on the emulator and when I open my application its state is not retained. I want the state to be retained in both the scenarios.
In the mnifest I have given the below entries,
android:alwaysRetainTaskState="true" for the root activity
android:launchMode="singleTask" for the application
I've got an android app that pulls a random 20 questions (rows) as a cursor from a SQLite DB and loops through all the questions to ask the user all 20 questions.
Is there some way to save the cursor's state/location when the activity is paused or stopped so that when the activity resumes the cursor is restored and in the same position as it was when the activity was paused/stopped?
In my android application i have a video list screen,a buffering screen and a videoplayer screen. As soon as the user clicks an item from videolist screen ,he is navigated to buffering screen and then to videoplayer. In the buffering screen i am using Async task and doing the loading process in on background process.
Now my issue is like the user if has selested a video then gets navigated to buffering screen.But if the user clicks back when he is in buffering screen then initially he is getting navigated to videolist screen but immediately after that again he is navigated to videoplayer screen.
What i would like to have is either the back button should be made disable in buffering or should prevent the player tostart if back is clicked.
I call WebView.clearHistory(), but I am still able to go back after doing so. I want to reuse a WebView, but I don't want the back button to allow the user to go back further than the current "session" of using the WebView. Anybody know what is the best way to handle this? I thought for sure that clearHistory() would do it.
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.
I have an application with main view having a search button. On clicking the search button, search results are displayed in a text view. When I hit the back button at this view, instead of navigating to the previous screen, application itself gets closed. Could anybody please let me know how to go back to previous screen.
I have 3 activities in my app: Activity1 -> Activity2 -> Activity3. Inside Activity3, if the user presses Back, I would like to return to Activity2. In Activity3's onPause event, I added a finish() statement. That's probably not even necessary, but I wanted to make sure this Activity gets cleaned up. This works fine. However, while in Activity3, if the user presses Home or starts a new app (through notification bar or some other means), I want both Activity3 and Activity2 to finish. If the user returns to this app, he should resume with Activity1.
I have figured out how to do one or the other, but I can't figure out how to handle both cases, if it's even possible. Can I trap the "Back" button in Activity3 and send a message back to Activity2 telling it not to finish()? It seems like the Activities follow the same lifecycle flow (Pause, Stop) regardless of what you do to send them to the background. Just to answer the question of why I want this behavior, imagine that Activity1 is a login screen, Activity2 is a selection screen, and Activity3 is a content screen. If I press Back from the content page, I want to be able to make a new selection. If I exit via any other means (Home, notification bar), I want the user to be "logged out".
I have a widget that contains 4 buttons to show 4 stock prices, each of them will launch into the same activity Quote.class to show stock details. In onUpdate(), it will set up the pendingIntent with extras with stock symbol. After I hit button A, it goes to Quote activity that shows stock A. Then I hit the BACK button to the homescreen, Quote activity calls onDestroy() and when I hit button B, stock B will show properly. However, when i hit HOME button after it shows stock A, the Quote activity only calls onStop without calling onDestroy(), then as i hit button B, it will call onStart() and it shows the same instance that shows stock A.
Originally I thought adding a flag in the Intent should solve this problem. But I have tried i.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK or FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_NO_HISTORY), none of them makes any difference.
So is there any ways to make it work? How can i remove the history stack from HOME button? How can I call onCreate in Quote activity and get new extras when i hit button B?
I have an activity that contains several user editable items (an EditText field, RatingBar, etc). I'd like to prompt the user if the back/home button is pressed and changes have been made that have not yet been saved. After reading through the android documentation, it seems like this piece of code should go in the onPause method. I've tried putting an AlertDialog in the onPause however the dialog gets shown and then immediately tears down because nothing is there to block the pause from completing.
i am new to android. i am showing Intent.ACTION_DIAL when my application starts..but when i clik back button it shows a activity page and again press back button it finishes the activity.i want when application starts dialler shown and if user cliks back button it calls finish() method
I looked around and although there are many related questions I didn't see one that answers my exact question:
I would like to create an app that runs in the background that provides the exact same functionality as the hard coded 'Back' button in all cases.
The reason? I (for example) have a Droid X, and it is BIG. it makes it extremely hard to use one-handed and having a swipe gesture function as a back button (like in Palm Pre for example) would greatly increase the ease of use.
as far as I'm concerned the app could just be one simple class that contains: 1) a listener for the 'back' swipe 2) a call to the physical hard button itself
Is this possible? are there built in APIs for the hard coded buttons that would allow me to call them without actually pressing them?
Again - I'm not interested in overriding the button, I'm interested in making a software call to it - or failing that, in emulating it's behavior in any and all states and other apps!
Please forgive the naivete of this post. I am a very novice programmer and really I just want to know whether this is possible before I start to devote myself to trying to build it.
First of all, maybe i went about this the wrong way in the first place. Situation is, i have a listview that when an item is clicked, it creates an intent and calls startActivityForResult() to another activity, to be able to edit the entries in the row. and that other activity after editing the required values, returns back to the calling activity, when the user clicks on a save button. The activity then uses the row Id to update the item.My problem now is that, if the user presses the BACK button instead, the application crashes. i have been looking around and see solutions like using Shared Preferences or onSavedInstanceState(), but i don't know where exactly i should be putting the code?
I understand that trying to capture home button clicks is a hack, but I need to atleast close my current activity when the user clicks on home button. Is there anyway I can tell the system to close this activity is the user clicks on home button? If so how can I do that? I need to do it as I am listening for location updates and I want to stop the updates and also need to trash any location that was available to me previously. I need to do this just in case any user while in that activity clicks on home button and changes the location settings.
My MAIN activity is spawning a child activity that contains a ListView. While this ListView is being populated (through an AsyncTask), an indeterminate progress bar is shown.However, assuming that I am an impatient user and I press the BACK button, the progress bar is cancelled but I am left with a blank screen. I have to press BACK one more time to go back to the MAIN activity.I would like the app to go back directly to the MAIN activity by pressing BACK only once. Can somebody point me in the right direction? I am thinking I should call finish() somewhere but I don't know where to put it.
I have various activitys on my app. I have a configuration Activity, and i want to put a cancel button, that, when user press this button, the configuration window get's closed and turn back into the previous activity.i search in google and i find something about calling cancel or dismiss functions, but i can't call them cause this is not a dialog, it's an activity
I have an application with 2 activities, LogonAct and MainAct. LogonAct is a logon activity which I want to force the user to go through each time they return to the application. I've set android:clearTaskOnLaunch="true" on LogonAct.
on the ui i am having a back button displayed. there are three activities say A,B,C. Activity A is splash screen. Activity B is home screen. Activity C is edit screen. on edit screen only i am having a back button. when the user press that i open the activity B which also contains some sort of http request and response. i want that the previous activity from stack should get displayed? how can i achieve that? i am able to open previous activity on pressing the back button of device? when i press back button on device there doesnt goes any http request? i want to achieve this behaviour when i press the ui back button.
In my game, I've got one activity starting another activity via an intent. When the user is finished with the second activity, they quit it using the back button. However, I have a problem: when this happens, the second activity is still running, even if it's quit with the back button.
My second activity will eventually give a "game over" message using a pop up window if there is no user input for a period of time. Problem is, when I back out of the second activity (where the game is happening) the "game over" message still appears eventually. This is how I know the second activity is still running. It even displays a "game over" message if my entire app is quit (on the Android OS).
How do I stop an activity completely when the user presses the back button?
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?
I have searched through this and a few other sites for the answer, but I have been unable to find it. I am trying to save a boolean and an int using onSaveInstanceState and onRestoreInstanceState, but I can't seem to get it to work. It doesn't crash or anything, but it either isn't saving it or it isn't restoring it, or I am stupid and have no idea what I am doing.
Here is what I have for my activity, do I need to have it in my onCreate somewhere or something?
I tried putting stuff in the onStop, but it crashes, which is why its empty, in case that matters, thanks in advance
I have two activities. The first is a list where the user selects one of the items which takes them to a second activity showing the details of the item they selected. When the user clicks the back button I want the app to return to the first activity.
Is there anything special i need to do to make this happen?
Right now when I click the back button from the second activity it exits the app just like the home button would.
Here is how I am starting the Second Activity. startActivity(new Intent(getApplication(), SecondActivity.class)); finish();
I am writing a application where I am dealing with 4 activities, let's say A, B, C & D. Activity A invokes B, B invokes C, C invokes D. On each of the activity, I have a button called "home" button. When user clicks on home button in any of the B, C, D activities, application should go back to A activity screen ?