Threads or ASyncTask?

by jfbaro » Wed, 14 Apr 2010 02:29:39 GMT


Sponsored Links
 Hi,

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?

Could anyone help me?

Cheers

--



Threads or ASyncTask?

by MobDev » Wed, 14 Apr 2010 15:20:41 GMT


 I am just making a wild guess here, and I hope more experience people
will support or deny it (Mark, are you awake yet ? ;) ) but this might
be a good scenario for a Service ?




--


Sponsored Links


Threads or ASyncTask?

by Streets Of Boston » Wed, 14 Apr 2010 22:24:24 GMT


 Depends.

But since the OP mentioned Notifications, i guess the search results
should be presented even when the user left the application. If so,
yes, then a Service would be best.

Still, i would use an AsyncTask (inside the Service) to do the actual
work. This way you'll be sure that the client's call to the Service
will never be blocking.





--



Threads or ASyncTask?

by Mark Murphy » Wed, 14 Apr 2010 23:29:36 GMT


 


Nope, I'm not awake.




Agreed. A service is a container for logic; a service needs asynchronous
operations as much as an activity does.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Development Wiki:  http://wiki.andmob.org 

--



Other Threads

1. Try/except handling for PostMethod?

Hi all

I'm using a PostMethod, and wondering what try/except handling I
should use.

The exception handling here seems to work okay in most scenarios, but
is there anything I might be missing? In particular, I'm wondering
whether this handles the network connection going down midway through
the upload.

                PostMethod method;
                method = new PostMethod("blah/");
                try {
                        Part[] parts = {
                                        new StringPart("blah", blah),
                                        file };
                        method.setRequestEntity(new 
MultipartRequestEntity(parts, method
                                        .getParams()));
                        try {
                                client.executeMethod(method);
                        } catch (java.net.UnknownHostException uhe) {
                                //handle error
                        }
                  responseString = method.getResponseBodyAsString();
                  int statusCode;
                  try {
                         statusCode = method.getStatusCode();
                  } finally {
                         statusCode = 0;
                  }
                  method.releaseConnection();
                  if (statusCode == 200) {
                                //do stuff
                  } else {
                                //do other stuff
                  }
                } catch (Exception ex) {
                        return false;
                } finally {
                        method.releaseConnection();
                }

-- 

2. Ask kalo ganti rom

Guys....

Kalo kita ganti rom, Full Wipe termasuk Wipe EXT...., trus yg di SDCard itu kan banyak Folder2 bekas rom yg dulu, itu perlu di hapusin/delete atau nggak ? -- Jus* ^ owner white dream ^ ~ send using pc jangkrik krik krik ~ $ www.cash-flowing.com $ -- "Indonesian Android Community [id-android]"

3. How integrate my Settings Activity into Settings apk

4. how to monitor the activities launching in real time, so I can count how many times it has been launched?

5. Getting Bitmap of all the Views in ViewFlipper?

6. application installer

7. Panduan memilih hp android