asynctask

Android: How can I pass parameters to AsyncTask's onPreExecute()?

I use an AsyncTask for loading operations that I implemented as an inner class. In onPreExecute() I show a loading dialog which I then hide again in onPostExecute(). But for some of the loading operations I know in advance that they will finish very quickly so I don't want to display the loading dialog. I wanted to indicate this by a boo...

AsyncTask threads never die (Android)

Hey everyone! I'm new to Android programming and I'm using AsyncTasks to fetch data in response to the user pressing a button. This works well and keeps the interface responsive while fetching the data, but when I checked out what was going on in the Eclipse debugger, I found out that every time a new AsyncTask was created (which is qui...

Android : Loading an image from the Web with Asynctask

How do I replace the following lines of code with an Asynctask ? How do you "get back" the Bitmap from the Asynctask ? Thank you. ImageView mChart = (ImageView) findViewById(R.id.Chart); String URL = "http://www...anything ..."; mChart.setImageBitmap(download_Image(URL)); public static Bitmap download_Image(String url) { //-...

ProgressDialog in AsyncTask throws an exception

I'm trying to make a simple ProgressDialog appear while my AsyncTask is fetching data. In my onPreExecute() method I have this: pd = ProgressDialog.show(c, "Loading...", "Please wait"); c is the context passed into the constructor of my AsyncTask from this.getApplicationContext(). Unfortunately, I keep getting an exception with this m...

How to stop service after AsyncTask finished?

I have a service, that requests another class, which launches an AsyncTask Service->Weather Class->Execute Method->Asynctask->Execute this is launched in the service by new Weather(this).execute(); // the execute is a method of the class, not of the AsyncTask how do I detect in Service that the AsyncTask finished so I can call stopS...

Timer across the multiple activities

i have an android app with several activities. I need to start a timer when the first activity starts and end the timer when the last activity starts and show the elapsed time. How can i use Asynctask to do this. ...

AsyncTask: Is onPostExecute guaranteed to run after all calls to onProgressUpdate?

Hey all, I would like to know if it is possible to get 'leftover' calls to AsyncTask#onProgressUpdate after AsyncTask#onPostExecute has been called? I am setting text on the same TextView using both of them, and I don't want to set text such as "Done!" and then have it overwritten at a later point by text such as "Almost there - 90%" ...

Issue when setting a ListView in a AsyncTask class

Hi, I'd like to set a ListView to data I get from a web service. I get the data in a AsyncTask instance, but when I try to set some of my ListView attributes, it crashes (on line "lv.setVisibility(View.VISIBLE);"). Anybody can help? thanks public class Atable extends Activity { private EditText mSearch; private static final i...

loading MapView from Main Activity slow animation almost hangs for a moment

i have the following code in a TabHost/TabWdiget for an activity in a Tab that has a ListView that calls my MapView if(_list.get(position).enabled) { convertView.setOnClickListener( new OnClickListener() { public void onClick(View v) { _context.startActivity(i); } }); } When the animatio...

Use AsyncTask to add items to list view individually.

I am trying to add ListView items one by one. So if I have say -- 60 items -- the application would add the views to the list view one at a time -- thus showing the user that the application is loading more things. This is my code: try { JSONArray j = getTaggsJSON(); Log.v(TAG, String.valueOf(j.length())); a =...

Android app works on WiFi, in debug mode, or on emulator, not on cell network

I have an android application that parses some HTML, downloads an image, and displays it. I'm using an AsyncTask to do the HTML parsing and image downloading, but that shouldn't be relevant. I never have a problem when I'm on WiFi on my phone, when I'm using the Eclipse debugger on my phone, or when I'm using the emulator. When I have my...

AsyncTask not generic?

Hi 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 arg...

Android : CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views

I have an issue with the following error in Android: CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views It appears to happen when I try to update a Textview in my Activity, the call to update the TextView is from within my Activity but I still get the above error. I have...

Returning Data from AsyncTask Resulting in Null Pointer Error

Hello, 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 causi...

Common class for AsyncTask in Android?

Hi, I have a common class say for eg Class A which extends AsyncTask and has all the methods implemented i.e. onPreExecute, doinbackground and onPostExecute. Now, there are other classes which want to use Class A object. Say Class B uses class A in the below manner A a = new A(context) a.execute(url) Then i fetch the result in get ...

Android : can AsyncTask return in another thread than UI thread ?

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. Howe...

onPostExecute on cancelled AsyncTask

Does onPostExecute execute if the AsyncTask has been cancelled? If it does execute, is it safe to say that I should always ask if the task has been cancelled (isCancelled) at the start of onPostExecute, before doing anything else? ...

External AsyncTask class with ProgressDialog [Update: and returning back?]

*Updated: (See below)*I have been looking around for couple of days and can't find a straight answer to this. Some say it possible to some say to accomplish some say it's not. I am getting crazy on this. What I want is just to have the AsyncTaskTask showing a progressbar an external class. To do this I am passing the context as you ca...

Android: How to download a .png file using Async and set it to ImageView?

Hi everyone. I've got the URL of a .png image, that needs to be downloaded and set as a source of an ImageView. I'm a beginner so far, so there are a few things I don't understand: 1) Where do I store the file? 2) How do I set it to the ImageView in java code? 3) How to correctly override the AsyncTask methods? Thanks in advance, will h...

Instance variable of Activity not being set in onPostExecute of AsyncTask or how to return data from AsyncTask to main UI thread

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 ...