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. Initiating CSD connections?

Does anyone have information about initiating Circuit Switched Data
connections from Android?  I don't see any part of the API that
provides this functionality, but maybe there's a character device that
I can access directly on the G1?


- D


2. Android and bluetooth


I have just started developing a new android app which needs to access 
bluetooth. But I came to know that android 1.0 doesnt support bluetooth, and 
has no API.
is it? is there any other way to use bluetooth? 

Its really surprising me that android has no support for bluetooth,and 
developers will not be able to develope apps which uses bluetooth.



3. Fwd: Emulator crash

4. Filesystems (yaffs2, jffs2 and nfs)

5. MyLocationOverlay monopolizing location updates?

6. Regarding video file playback in android emulator

7. how to write a file on SD card in android?