Android :: Instance Variable Of Activity Not Being Set OnPostExecute Of AsyncTask - Return Data From AsyncTask

Jul 28, 2010

I'm trying to figure out the correct way to create an AsyncTask to retrieve some data from the internet and then to take that data and bundle it up in an Intent and pass it to a new activity(A list display). So in the first activity I just have an EditText and Button. In the event of an OnClick the task should be called and when it is finished the data should be bundled inside an Intent and passed to the next Activity. The problem is when I take the results from onPostExecute and set them to an instance variable of the main activity, that instance variable is still null when the task is complete. Here is the barebones version of the code:

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

When I debug the application I see onPostExecute does contain a valid PlacesList full of results, so why is the instance variable places set to null after the task is executed? I am going about "returning data" from an AsyncTask incorrectly?

Android :: Instance variable of Activity not being set onPostExecute of AsyncTask - return data from AsyncTask


Android :: AsyncTask - OnPostExecute And OnCancelled?

Sep 10, 2010

onCancelled. onPostExecute seems to be skipped everytime I run the asynctask, the file downloads, no problem, but the dialog is still there. As for the cancel button, it doesn't seem to reach onCancelled. Can anyone wee what I'm doing wrong?

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

View 4 Replies View Related

Android :: OnPostExecute Not Called After Completion AsyncTask

Aug 31, 2010

For some reason my onPostExecute() is not called after my AsyncTask finishes.

My class decleration:

CODE:.......

Everything works fine, my doInBackground() completes successfully and returns a Boolean but then it just finishes.

View 2 Replies View Related

Android :: Way To Return Result Of AsyncTask

Jan 21, 2010

According to my research, which includes reputable sources (Mark Murphy et al), the most preferred way of polling a remote source and presenting said data to the user is by creating a service and using AsyncTask within that service to do the polling. I have done that.But, when I read the docs there seem to be several "Threading Rules" that conflict with this way of doing things: "The task instance must be created on the UI thread." and "execute(Params...) must be invoked on the UI thread." As stated, I have created the task instance on the Service thread (not the UI thread). Am I missing something? Also, when the AsyncTask finished, I sent out a Broadcast on onPostExecute, which is then picked up by the Activity, telling it to retrieve the final value again from the service (since I couldn't obviously update the UI from the service). I couldn't figure out any other way to return the result of the AsyncTask. Is this the correct practice?

View 8 Replies View Related

Android :: AsyncTask Return In Another Thread Than UI?

Jul 21, 2010

Android documentation says that AsyncTask postExecute() is called on the UI thread. I was under the impression that postExecute() was called from the Thread where execute() was called : I have been using an AsyncTask in a background Service with its own thread, and postExecute() was called in the service thread, not the main thread. However, I recently had an issue with the postExecute() not being called at all, while an exception was thrown : " sending a message to a Handler on a dead thread". How is it exactly :

- shall AsyncTask be used ONLY from the main thread ?
- if not, in which thread postExecute() is supposed to be called : always the UI thread, or the execute() calling thread ?

View 2 Replies View Related

Android :: AsyncTask And UI Activity

Aug 9, 2010

I know this is not how an async task should behave but my question is how to "block" the user while executing it.My need is the following: I have my own backup/restore process and I have an async task to run these two actions. The backup is fine, I can warn the user when the backup is done and that's just fine But my problem is about the restore process. When the user click on restore he shouldn't be able to make any change in the application (and anyway don't want to because he would lose all his changes).I understand that having the user blocked while restoring (or maybe with a progress bar) is not a best pratice but I do not see any other possibility in this context.

View 7 Replies View Related

Android :: Fetching Data - Responsebody - HttpClient In An AsyncTask And Returning Data

Mar 16, 2010

How I'm able to do what I've written in the topic. I've looked through many tutorials on AsyncTask but I can't get it to work. I have a little form (EditText) that will take what the user inputs there and make it to a url query for the application to lookup and then display the results.

What I think would seem to work is something like this: In my main activity i have a string called responseBody. Then the user clicks on the search button it will go to my search function and from there call the GrabUrl method with the url which will start the asyncdata and when that process is finished the onPostExecute method will use the function activity.this.setResponseBody(content).

This is what my code looks like simpliefied with the most important parts (I think).

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

View 1 Replies View Related

Android :: Executed ASyncTask In Activity But Not Working

Feb 18, 2010

private class ExecuteLocations extends AsyncTask<String, Void, Void>{
private final ProgressDialog dialog = new ProgressDialog(ListProfiles.this);
protected void onPreExecute() {
//this.dialog.setMessage("Starting pre-execute...");
//this.dialog.show();
} @Override protected Void doInBackground(String... arg0) {
check_profiles_lm=(LocationManager) ListProfiles.this.getSystemService(LOCATION_SERVICE);
myLocListen = new LocationListener(){
@Override public void onLocationChanged(Location location) { HashMap params = new HashMap();
params.put("lat", Double.toString(location.getLatitude()));
params.put("long", Double.toString(location.getLongitude()));
postData("http://mydomain.com",params);
} @Override public void onStatusChanged(String provider, int status,Bundle extras) {
} @Override public void onProviderDisabled(String provider) {
} @Override public void onProviderEnabled(String provider) {
} };
check_profiles_lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30000, 0, myLocListen);
return null; } protected void onPostExecute(final Void unused) {
if (this.dialog.isShowing()) { //this.dialog.dismiss();
} //Do something else here
} }

Basically, my objective is:
Constantly post the latitude/longitude to my website every minute or so. Of course, I want to do this in another thread, so it doesn't mess up my UI thread. This AsyncTask is supposed to solve that but it's bringing up an error and I don't know why. What can you do to accomplish my objective? It's very simple...just scan location and post to web every minute, in the background. By the way, my onCreate method is like this. That's basically it.

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new ExecuteLocations().execute();
setContentView(R.layout.main_list);
}

View 2 Replies View Related

Android :: AsyncTask Won't Stop Even When Activity Has Destroyed

Mar 27, 2010

I have an AsyncTask object which starts executing when the activity is created and does stuff in the background (downloads upto 100 images). Everything works fine but there is this peculiar behavior which i'm not able to understand.For eg: when the android screen's orientation changes then the activity is destroyed and created again. So I override the onRetainNonConfigurationInstance() method and save all the downloaded data executed in the AsyncTask. My purpose of doing this is to not have AsyncTask run each time activity is destroyed-created during orientation changes, but as i can see in my logs the previous AsynTask is still executing. (The data is saved correctly though)I even tried to cancel the AsynTask in the onDestroy() method of the activity but the logs still show AsynTask as running.This is really strange behavior and would really be thankful if someone can tell me the correct procedure to stop/cancel the AsynTask.

View 1 Replies View Related

Android :: Activity.finish() With AsyncTask Still Running In Background?

Apr 28, 2010

What happens on Activity.finish() with an AsyncTask still running in background?

Does it just pop the Activity off the Activity Stack, but wait to destroy the Activity object until the AsyncTask fully completes (since the AsyncTask is an inner class of my Activity)?

Also, would it act any differently if the AsyncTask were a public, non-inner class that held no references to the instance of the Activity?

View 1 Replies View Related

Android :: Problem Long Running AsyncTask With Reference To Activity

Jul 24, 2010

I have an AsyncTask that scans the file system and publishes progress through Notifications. To do this I need a reference to the current Activity in the AsyncTask.

I also don't want to kill the task when the activity is destroyed. How do I avoid leaking the activity and everything it references on each configuration change?

One possibility is to remove the reference in OnPause() to be sure it is gone when the Activity is destroyed, but that would mean notifications stops coming as soon as you leave the activity which is no good.

Isn't there a recommended way of dealing with AsyncTasks in this way?

View 12 Replies View Related

Android :: AsyncTask To Run On Activity Start Fails After Previously Getting Cancelled

Sep 10, 2010

I am using an AsyncTask to fetch the ring tone for a contact when my application starts, it works fine until after my Activity closes a couple of times during the AsyncTask, after this happens the AsyncTask will only ever get to onPreExecute() and never doInBackground, so I can never fetch the ringtone then until either a force stop or device restart.

Why this might be happening? Why the AsyncTask would get to onPreExecute but then never run doInBackground()?

Here is my code: (Following the Shelves source code)

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

And onAddRingtone() is used in onCreate and onCancelRingTone() is used in onDestroy() as well as where you can see if in the code above. I have spent 3 days on this and I haven't been able to find a solution? Am I taking the wrong approach? Using cancel wrong? Is there a bug?

View 1 Replies View Related

Android :: Trap In TabHost When AsyncTask Delays Set Content View At Activity Startup

Nov 3, 2009

I've got a tab host activity started from a home screen shortcut. When my application starts it downloads information from a server using an AsyncTask. In the onPostExecute method of the AsyncTask I call setContentView to display the TabHost.When I start the homescreen shortcut by tapping on the shortcut using my finger everything works as expected, I download the information from the server and display the TabHost with the information in the tabs. However starting the application by navigating to the shortcut with the mouse wheel and then clicking on the shortcut with the mouse wheel leads to a trap in the framework code as soon as my application starts. This looks like a simple fix since mCurrentView is null at the time that this method is called - can this issue be addressed? Does anyone know of any workarounds?

View 5 Replies View Related

Android :: Returning Data From AsyncTask Resulting In Null Pointer Error

Jul 20, 2010

I am trying to do what I think is a fairly simple task to authenticate a user on my server. I am using AsyncTask as a private subclass of my Activity, however when I try to populate the user object after authenticating it keeps setting it to null. Is there something strange in how the onPostExecute() method is called that is causing this? I originally had the AsyncTask as its own class but ran into the same problem, so I am try to solve this using a private subclass.

View 2 Replies View Related

Android :: Acitivity Managing - Always Starts New Instance Of Activity And Fetch Data From DB

Nov 17, 2010

I have been in problem of the Activity life-cycle. All though i read lots of docs on it put on getting clear picture on it. I have Activity A. In that activity I have menu options. If we click any option it opens the respective activity like if i click on 2nd button it opens Activity B Now again Activity B has same options into it. When user clicks on 1st button then i need to go back to activity A. So using this. Intent intent = new Intent().setClass(context, Articles.class); startActivity(intent); So always it starts new instance of activity and fetch data from DB. I want something like Activity A can be resumed back as it was.

View 6 Replies View Related

Android :: Threads Or ASyncTask

Apr 6, 2010

I am working on a simple application (studying purposes) which list all the files from a selected folder. On top of that I would like to have a search feature where the user can search for files (the code for that is already in place). Now, I was thinking about having the search running in the background somehow, whilst the user can still navigate, create folders, copy, sort and do other stuffs normally. When the search finishes the user would get a notification and then could click on it and go to that activity (It ideally should be the same ListView I already use for browsing the files, I would just need to update the Adapter there with the latest processed data after clicking in the notification). What's the best answer for that? Threading or AsyncTask?

View 4 Replies View Related

Android :: AsyncTask And Queries

Dec 27, 2009

Can anyone point me to a good example where a AsyncTask queries a local SQLite database and then updates the UI successfully. I have a database which I query using doInBackground... create a new custom SimpleCursorAdapter (overriding onViewBind), return the adapter (SimpleCursorAdapter), then in postExecute() create ListView adapter which is set to the the SimpleCursorAdapter, that was returned, then I set the listview adapter using SetAdapter(adapter);...

For some reason I throw an exception on fillWindow.java:200....

View 2 Replies View Related

Android :: AsyncTask On A Button

Jul 15, 2009

My application parse an xml file dans display data in a list view. On start of application i load data using an AsyncTask. A Progress Dialog is display during the load. This part works fine.A button in the application make it possible to reload the data. I would like to run the AsyncTask but the sytem say i can't alter view in other thread. I have also read an AsyncTask can't be run another time So i would like to know what is the best way to do this and not to have the "application not responding" message.

View 5 Replies View Related

Android :: Timing Out An AsyncTask?

Apr 9, 2010

I know how to use AsyncTask in a standard manner to manage operations that are in the background in relation to a UI thread.However,I want to run a task in the background which might run for a very long time under certain circumstances. In these cases, I would like to force the background task to fail if it runs for an excessive amount of time.I know that I can invoke the "get(long timeout, TimeUnit unit)" method of AsyncTask in my UI thread in order to terminate my background task if it runs too long. However, in that case, my UI will block while this "get()" command is waiting.There are probably other drawbacks to directly calling "get()" in this manner, not the least of which being an evil interaction with the "done()" method of AsyncTask's contained FutureTask object, which itself is calling "get()" at least this is what I see when I look at the source code for AsyncTask.

View 10 Replies View Related

Android :: ViewSwitcher With AsyncTask

Jul 5, 2010

I have an activity that needs to do some stuff in the background. When the background is done, I want it to load a new activity.I can successfully kick off the async task and using using ViewSwitcher I can show a nice progress dialog.However, when the user hit 'back' or 'close' from the new task, I want them to see the main screen of this task again. So, I use the showPrevious() after I start the new Activity, but I see the screen switch from the loading window back to the main window BEFORE the new Acitivity is launched.How do I get it to switch after the new activity, or when they come back from the new activity?I tried onRestart() and onResume() but both of them seem to give me a view of -1 that I couldn't do much with.

View 2 Replies View Related

Android :: Timing An ASyncTask

Sep 20, 2010

I'm running a network service within an ASyncTask. I want to be able to time the task, and after a certain period of time interrupt it.Is there a simple way to do this? Basically, when the doInBackground() methods starts, I want to say "If it hasn't completed in 30 seconds, do something else".

View 2 Replies View Related

Android :: How To Use AsyncTask From Thread?

Jul 29, 2009

I'm developing a game based on SurfaceView and a game thread for the whole game thing.Now I want to do some HTTP requests triggered on events inside the thread. They should of course be asynchronous, so the game doesn't stop. I found AsyncTask to be a neat way to do this but I'm having trouble implementing this at the moment. Maybe I misunderstood the concept of AsyncTask,I don't know it just drives me nuts as I read docs and blogs and still I don't get it. So sorry if that's a dumb question but I'm mad of thinking about it.

View 4 Replies View Related

Android :: Asynctask Threads Never End

Mar 13, 2010

while debugging and app that uses AsyncTask to record audio and update UI I noticed that everytime that an AsyncTask object ends running (finishes doInBackground and onPostExecute or on Cancelled it´s thread stays alive (running status).At least for me that should not be the behavior of the class since the doInBackground task may not stay running forever (as an example the android manual says that a status bar should be updated by an asynctask, and it won´t last for the whole app running time).Is there anything I´m missing, as a method to destroy it, or should I just ignore and keep creating threads as I need and the VM will handle them as it needs resources?

View 9 Replies View Related

Android :: AsyncTask Not Generic

Jul 18, 2010

When I try to compile to following code, I get two errors:

Description Resource Path Location Type
Syntax error on token "void", invalid Expression AsyncTask.java /AsyncTask Project/src/org/me/asynctask line 19 Java Problem

Description Resource Path Location Type
The type AsyncTask is not generic; it cannot be parameterized with arguments AsyncTask.java /AsyncTask Project/src/org/me/asynctask line 25 Java Problem

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

Obviously AsyncTask IS a generic (http://developer.android.com/reference/android/os/AsyncTask.html#execute so why do i get those errors?

View 2 Replies View Related

Android :: How To Get XML Using AsyncTask And Timer?

Jan 7, 2010

In order to get XML data from a server repeatedly, I'm attempting to use AsyncTask and Timer as per Mark Murphy's suggestion. I get the following error:01-07 16:11:26.705: ERROR/AndroidRuntime(729): Caused by: java.lang.Runtime Exception: Can't create handler inside thread that has not called Looper.prepare()I'm using SDK 1.5 with Eclipse on Windows.I've looked in documentation, on StackOverflow and in the Android Developers group, but I'm not clear what's causing the error or how to fix it.I can get the data once - i.e. without Async and Timer - and parse it via SAX without problems.s: I'm quite new to Android.

View 5 Replies View Related

Android :: SDK1.5 - AsyncTask ?

Apr 10, 2010

My program was going wonderfully. It is a search engine that connects to our back end database by sending Get requests to our server and displays the results. I've managed to get it to query my server and back end database, return results using JSON, return the first headers and pour them into a ListView widget in the main activity. Then when the user clicks on one of the headers it then sends another query from a sub-activity. It then parse those results and format them neatly into a WebView embedded into the sub-activity.

All this works perfectly. That is until I come to make a second query on the main activity. Listed below is my stack trace of where the error happens. I think I know why this is happening, but obviously not clearly understanding it.

I think it is because I am trying to call AsyncTask again. I remember reading that the AT can only be called once, but I presumed quite wrongly that this meant you can not do concurrent calls. I thought that once an AT had done it's task it was cleared and then could be called again, but this does not seem to be the case. Is it because of AT attempts at more than one call ? If so, would I be better changing that section into a Handler with a Runnable on the main activity?

-----Stack Trace----

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

View 3 Replies View Related

Android :: AsyncTask And Contexts

Dec 16, 2009

I'm working out my first multi-threaded application using Android with the AsyncTask class. I'm trying to use it to fire off a Geocoder in a second thread, then update the UI with onPostExecute, but I keep running into an issue with the proper Context.

I kind of hobbled my way through using Contexts on the main thread, but I'm not exactly sure what the Context is or how to use it on background threads, and I haven't found any good examples on it.

Here is an excerpt of what I'm trying to do:

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

It keeps failing at the sixth line there, because of the improper Context.

View 3 Replies View Related

Android :: Using ThreadPoolExecutor And AsyncTask

Feb 12, 2010

When using ThreadPoolExecutor can I use AsyncTask as the Runnable in my queue? Or does this defeat the purpose?

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

View 2 Replies View Related

Android :: AsyncTask Bug On HTC Sense

Mar 5, 2010

Im using HTC Hero with HTS sense. Im experience that sometimes AsyncTask not will run doInBackground method on execute();

View 2 Replies View Related

Android :: Handler Vs AsyncTask

Mar 26, 2010

I'm confused as to when one would choose AsyncTask over a Handler. Say I have some code I want to run every n seconds which will update the UI. Why would I choose one over the other?

View 3 Replies View Related







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