Thread instead of Service, is it safe ?

by Derek » Mon, 10 Nov 2008 17:26:17 GMT

Sponsored Links

I've an Activity A that starts a Thread T which download a file
through HTTP. It works fine. If I close my Activity (back button)
while downloading, it is destroyed (onDestroy called) but download
Thread still continue and download is completed fine.

For testing purposes I've moved my Thread T into a Service and my
Activity starts the Service now. It's a little bit complex to write
(for callbacks) but it works fine too.

What it the best approach ? From the documentation I think Service
seems better to make sure the download Thread will continue even if
the Activity is destroyed ?


Thread instead of Service, is it safe ?

by hackbod » Mon, 10 Nov 2008 18:27:31 GMT

 Correct, use a Service, your process can be killed any time after
Activity.onPause() returns if there isn't another Activity, Service,
etc active in it.


Sponsored Links

Other Threads

1. Trouble Opening Files via Intent

Hi All,

I posted this in the beginners section, but received no response.
Sorry if it is bad etiquette to re-post here, it just seems that there
is a lot more activity in this list.

I am running through the FileBrowser tutorial over @ and
have it working fairly well, but the one thing I cannot get working is
Opening files when they are clicked on.

I always seem to get a "ActivityNotFoundException: no activity found
to handle { action: android.content.Intent.ACTION_VIEW data=file:///
sdcard/myfile.txt} "

My openFile() function looks like this:

    private void openFile() {
        try {
                Intent myIntent = new
Intent(android.content.Intent.ACTION_VIEW, Uri.fromFile(myFile));
        } catch (ActivityNotFoundException e) {

Can anyone see any problems with this? Is it just that there are no
Apps registered to handle opening of .png images and .txt files? Or is
my code wrong?



2. Fetch from phone book - crashes

I was trying to fetch the contact number and name from the phone book.
But while querying for the content, it crashes. Below is the code that I
was using. 
ContentResolver cont = getContentResolver();

Cursor c = cont.query(Phones.CONTENT_URI, null, null, null, null);  //
crashes here


// Create an array to specify the fields we want to display in the list
(only TITLE)

String[] from = new String[]{Phones.NAME};

// and an array of the fields we want to bind those fields to (in this
case just text1)

int[] to = new int[]{};

ListAdapter adapter = new
SimpleCursorAdapter(this,R.layout.contacts_row,c,from,to );






3. Building android emulator apps

4. bug in messaging (sms)

5. market place not displaying uploaded applications or upload button.

6. Reacting to incoming email

7. Proximity Alert ala Locale