I currently have a listview and when a user presses an item on the list it loads up a new activity which starts and binds to a service. When, i press back to go to the listview and I press the same item again, i am getting an unable to destroy activity error. any idea why?
Considering you didn't post any code for us to look at, I'm guessing that you never unbind your Service. You can find the same issue here.
Related
Here's the scenario I'm struggling with:
The user starts my app and presses the Download button. The app starts a download on its own (with an AsyncTask, not using the System DownloadManager) and shows progress in the notifications. Now the user presses the back button, which finishes the activity. Except the AsyncTask and notification keep going, even with their "parent" activity finished.
Now the user goes back into the app by clicking on the notification. Because the last activity was finished and onDestroy() was called, a new activity gets created. The problem is this new activity has no idea that an AsyncTask from a previous instance of itself is still going, and so it shows the Download button again. Clicking this creates a duplicate AsyncTask and notification. Not good.
How can the new activity get a handle on this "lost" AsyncTask so that it can get information from it?
Ideas I'm not looking for:
Blocking/overwriting onBackPressed
Constantly sending info through SharedPreferences
I have an app that contains a sequence of listviews, and those lists are populated with data retrieve from a webservice. I want to refresh this data when the user presses back to go to the previous list.
I have currently tried overriding the onWindowFocusChanged method, but this doesn't work, since when I start a webservice download, I bring up a progress dialog and close it upon completion. This causes a recursive effect (the dialog closes and gives focus back to the list activity).
Is there any way I can get when the activity is first shown? Similar to viewWillAppear for iOS?
Just override onResume() in the Activity. Just make sure to do whatever internet communication you do in a separate thread.
I suppose the title is a bit confusing but here is what I'm trying to do:
I have a class called ManageClass which lists the entries of a database. I have written another private class within ManageClass which extends AsyncTask so that I can display a progress dialog while I'm getting the data from the database. Now when I click on an item I create a new Intent which takes me to my ViewItem class. I've added a button there so that the user can delete that particular entry that he/she is looking at. All of the above work fine.
Now I want after deleting that entry to kill the activity and go back to the previous one (the one displaying the list) but I want to refresh the listings.
My problem is that I cant use onResume() cause it will also be called when the activity is resumed after the AsyncTask finishes.
Could anyone help me with that? I'm really stuck... all ideas are welcome!!!
If I understand your app workflow you should use startActivityForResult instead of launching a new Activity via intent.
Look at here fore some example
Basically you can launch a new Activity and wait for a result via callback on the "opener" activity. so you can avoid to put your logic into onResume method
I've been trying to figure out how to stop all threads when my application is paused (when the 'Home' button is pressed) and I just can't figure it out.
Here's what I have: one main activity containing a tab host, every tab host has a list, when one item in the lists is clicked a new activity with details is started. Each list is within its own activity which starts an updater thread that makes sure the list content is always up to date.
Here's what I've tried: I've tried using the onPause(), onResume(), onStop() and onDestroy() events. The problem is that if I use either the main activity of the activity that holds a list to monitor for those events, they get called every single time an item from the list is clicked, as well as when the 'Home' button is actually pressed, so there's no way to distinguish between the situations.
Am I missing something? How is this usually done?
This is a pretty good indication that your design is flawed. You shouldn't ever have threads laying around that you can't account for or that don't finish themselves.
Each list is within its own activity
which starts an updater thread that
makes sure the list content is always
up to date
This kind of thing should be done in a service.
they get called every single time an
item from the list is clicked
This is how those events work. As soon as your activity is no longer visible (ie your new activity comes in front), it goes to onPause() and possibly onStop(). You have to account for this. You can't fight it, or work around it.
I'm looking to find out how to stop an activity instead of resuming upon the click of the item on the notification list. Any ideas?
Overload onNewIntent in your activity and when you get the intent from the pending intent just call finish()
Your activiy will need to be a singleInstance activity though. Otherwise, a new activity will get created on the task stack when the notification item is clicked.
Can you be more specific about what you're doing. Are you trying to write another Task-Killer-like application? or perhaps some kind of music player application? Telling us about the kind of application you're writing can help us help you.
By the way, using the term "resuming" shows that you haven't fully understood the Activity lifecycle yet. onResume is for resuming the UI thread. onRestart is the one that's used for restarting the Activity.