Android :: AsyncTask Preformance Issue On Many AsyncTasks Spawning

Sep 19, 2010

I'm about to create a lazy image loader for images both from device and from the web for a ListView. I'm thinking of what to use and how, on one hand i can use a thread that pools my request (always running, and i can attach a view and an adapter and it will handle the image loading for me), cache my allready loaded images and checks for the visibility of the images before i load so i wont do unneeded job.

I had another thought of using the AsyncTask like many suggest in the forum. Terhe is one drawback though.I see that many use new MyTask().execute(urls); this presents a problem if i want to start loading and stop loading images on demand. If i use the async task per image then i need new async task for each image, that's a lot of 'new' to make, i can use a pool, but if too many async tasks are stuck, i will still create about 150-200 asyc tasks, too many for my taste...

What do you guys think ? i think a thread will do a nicer job here:
1. keep on running till killed
2. try to get a job from the queue, if not jobs, wait.
3. if a job is available, get it and start processing.
4. each request is processed alone,serially and blocks the thread.
5. once does goes on with '2'.
6. each enqueue that is done by the adapter using startLoadingImage() for views that need to be displayed will create anew job and call notify on the wait lock.

I can optimize this code with a pool of threads if i want several GETPOST requests in parallel. Also I'm caching the images i already downloaded loaded for fast load on next access. the idea is to minimize GC and list's slagging.

Android :: AsyncTask preformance issue on many AsyncTasks spawning


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?

View 1 Replies View Related

Android :: Intent Service Not Actually Spawning New Thread

Sep 16, 2010

My IntentService is blocking my UI thread and I wanted to find out why. So I turned on profiling in the onStartCommand method of the IntentService and turned it off at the end of the onStartMethod. The working being done in between is web access with the Apache HTTP client.According to the profiler, the onStartCommand method of the IntentService is running on the main thread, not in a worker thread. Any idea what could cause this behavior?

View 3 Replies View Related

HTC EVO 4G :: Crap Battery Life - Boring Colors And Poor Preformance?

Aug 28, 2010

I'm just moving from AC. First just want to say what's up? I released a couple ROMs in my sub-forum if you'd like to bring your EVO to the max performance.Custom one of a kind look! Reply in the ROM thread and let me know what you think if you would! ANOTHER UPDATE TODAY 8-29-10. Including new (very sexy) notification bar and icons! Be lookin out. Custom ROMs - Android Forums. If you have any questions regarding my ROMs post in the link above. Just another little question, how many of you are rooted?

View 19 Replies View Related

HTC Hero :: Mail Process Keeps Spawning Although Not Used

Dec 9, 2009

I dont have push mail in hero configured nor have I ever touched that application. I only use the built in gmail application to send and receive mails. When I installed Taskiller, I noticed that I have this "Mail" process which is always there! if I kill it, after a few minutes, it will come back. So far I cant seem to isolate the problem and I am quite clueless about why this application is there, because it takes about 3 mb of memory.

View 3 Replies View Related

Android :: Concurrency Of AsyncTasks

Jun 26, 2009

I am replacing the multithreaded code in my app with the AsyncTask from 1.5. I found that two AsyncTasks do not work concurrently. I investigated a bit and found a workaround; I would like second opinion if my solution is right. OR if there is a better solution.

AsyncTask allows the app to do a task on a thread other than the UI thread. But IIUC, it only provides a single thread on which a queue of tasks is performed. Therefore, if one of the task is to wait on some event (n/w or sleep) then all other tasks will wait for it to finish.

To elaborate with the coding example: <code>

public class MyTask extends AsyncTask<...> { ... }

On the UI thread execute two tasks MyTask mt1 = new MyTask().execute(args);

MyTask mt2 = new MyTask().execute(args); </code>

In the above code both the execute calls will return immediately and free up the UI thread; however mt1 will be executed first and mt2 will have to wait until mt1 finishes.

Thanks to the android's open source, we can see implementation of AsyncTask. http://google.com/codesearch/p?hl=en&sa=N&cd=2&ct=rc#uX1GffpyOZk/core...

I copied AsyncTask.java as UserTask.java in my project and changed the value of CORE_POOL_SIZE to 5. This makes the thread pool to use 5 threads to multiplex the queued AsyncTasks. This indeed solved my problem. Now if mt1 blocks on a sleep; mt2 goes ahead and finishes its job.

Here are some questions for those who know more about AsyncTask implementation:

Is this work-around right? If yes, can the CORE_POOL_SIZE be made configurable in future, via an API call? Is there a solution by which multiple thread pools can be used?

Let me add that, I am aware that this is a phone and not a web server - I am not using 10s of threads to do network I/O. However a single thread is not sufficient for my app either.

View 5 Replies View Related

Android :: Periodically Executing AsyncTasks?

Sep 1, 2010

I am getting data from the server using AsyncTask. I need to update the data periodically.

View 3 Replies View Related

Android :: Pause And Resume AsyncTasks?

Mar 19, 2010

I have an AsyncTask that acts as a countdown timer for my game. When it completes the countdown it displays the out of time end screen and it also updates the timer displayed on the screen. Everything works fine, except I need to be able to pause and resume this when the pause button in the game is pressed.

If I cancel it and try to re-execute it, it crashes with an IllegalStateException.
If I cancel it and instantiate a new AsyncTask in its place the old one begins to run again and the new one runs at the same time.

Is there a way to cancel/pause the timer and restart it using AsyncTasks or is there a different way I should be going about doing this?

View 3 Replies View Related

Android :: Running Multiple AsyncTasks At The Same Time - Not Possible?

Nov 1, 2010

I'm trying to run two AsyncTasks at the same time. (Platform is Android 1.5, HTC Hero.) However, only the first gets executed.

Here's a simple snippet to describe my problem:

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

The output I expect is:

onCreate() is done.
bar bar bar
foo foo foo
bar bar bar
foo foo foo

And so on. However, what I get is:

onCreate() is done.
bar bar bar
bar bar bar
bar bar bar

The second AsyncTask never gets executed. If I change the order of the execute() statements, only the foo task will produce output.

Am I missing something obvious here and/or doing something stupid? Is it not possible to run two AsyncTasks at the same time?

I realized the phone in question runs Android 1.5, I updated the problem descr. accordingly. I don't have this problem with an HTC Hero running Android 2.1.

View 1 Replies View Related

Android :: Same Activity Called Twice - Multiple AsyncTasks?

May 8, 2010

I have three simultaneous instances of an AsyncTask for download three files. When two particular ones finish, at the end of onPostExecute() I check a flag set by each, and if both are true, I call startActivity() for the next Activity.

I am currently seeing the activity called twice, or something that resembles this type of behavior. Since the screen does that 'swipe left' kind of transition to the next activity, it sometimes does it twice (and when I hit back, it goes back to the same activity). It's obvious two versions of the activity that SHOULD only get called once are being put on the Activity stack.

Could this be from both onPostExecute()s executing simultaneously and both checking the flags each other set at the exact same time? This seems extremely unlikely since two processes would have to be running line-by-line in parallel...

A lot removed from this question since I was way off in what I thought was wrong. Nonetheless I found the answer here quite useful, so I have edited the question to reflect the useful parts.

View 1 Replies View Related

Android :: Super Slow Apps Caused By Large Number Of Unending AsyncTasks

Aug 11, 2010

I have no idea, but my app is stalling sometimes completely (not responding to touching the screen) I thought I was following all the rules for threading, but my app is apparently slowing down the Sprint EVO! I have never used an app as slow as my own. I don't get an ANR dialog, though I think I probably should get getting one. I have no idea how to make this application run like every other app I've ever used -- Not freezing. Is it not a good idea to have one HttpClient and keep a static reference to it for all Activities that want to use it? I used to create a new one each time, and thought that changing it to one sped it up. None of my AsyncTasks ever end. If I go to Activity A -> B -> C -> D the first time it will be smooth. I can press back but when I get back to A, its completely frozen, not responding to anything. That when I took that screenshot. I really have no clue what I am doing wrong. Should I manually kill my AsyncTasks on Activity.onPause()?

View 1 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 :: 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 :: 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

Android :: Asynctask - Get Response Of Any Particular URL Given

Oct 12, 2010

Tell about the "asynctask" used in android application. Currently I am working on an application where I have to create a Class in which I have to just get the response of any particular URL given. I this particular class I was told to perform this task by making use of "asynctask".

View 1 Replies View Related

Android :: AsyncTask DoInBackground Does Not Run

Nov 2, 2010

I'm having a problem with the AsyncTask class. It seems like my task stops working after creating 4 or 5 tasks.

Im having 2 activities. MainActivity which only holds a button that starts a second activity called ImageActivity.

ImageActivity is very simple. it got an onCreate that sets the layout, and then it starts a new AsyncTask that loads an image from the internet. This works fine the first few times. But than it suddenly stops working. The onPreExecute method is run every time, but not the doInBackground method. I have tried to simplify the doInBackground with a sleeping loop, and the same thing happens. I cant understand this behavour since the asynctask is both canceled and set to null in the onDestroy method. So every time i start a new ImageActivity, i also create a fresh AsyncTask.

I recreate the ImageActivity and the task by hitting the back button, and than clicking the button on the MainActivity.

UPDATE: Code that starts the ImageActivity (inside a button onClickListener)

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

The code above starts this activity

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

UPDATE:

I have tested using a combination of traditional Threads and runOnUiThread method, and it seems to work better. Now the thread runs every time.

View 2 Replies View Related

Android :: How To Use SQLite DB From AsyncTask

Nov 24, 2010

I've been using my Activity class to access my DB which made my program freeze sometimes.

So I decided to use AsyncTask instead to handle the DB.

My problem is I don't know how to instantiate my SQLite DB "TheDB" from AsyncTask's class

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

This worked fine on the Activity class, but it I dont know how to use it here

TheDB's constructor is TheDB(Context context) but this class is not a "context" so how can i use my DB here?

View 2 Replies View Related







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