Thread instead of Service, is it safe ?

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


Sponsored Links
 Hi,

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 ?

Thanks.
--~--~---------~--~----~------------~-------~--~----~



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. dragging objects in MapView

Hey
How does one drag and drop markers in a mapview? Locale has
implemented this nicely...

Alex

--~--~---------~--~----~------------~-------~--~----~

2. Not able to receive Android's Broadcast message .. !

Hi,

I'm trying to receive Android's Broadcast message say
MEDIA_SCANNER_FINISHED, but not able to do so.
Here is my code snippet:

public class MyBroadcastRec extends BroadcastReceiver
{
        MyActivityClass receiver;
        private final static String TAG = "MyBroadcastRec";
    MyBroadcastRec(MyActivityClass cntxt)
    {
        receiver = cntxt;
    }
    @Override
    public void onReceive(Context context, Intent intent)
    {
              String inte = intent.getAction();
              if( inte.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED))
              {
                   receiver.reportMediascannerEvent(); // calling
MyActivityClass' method
              }


}
}

I'm instantiating MyBroadcastRec class inside MyActivityClass.
here onReceive() method should be called as soon as MediaScanner
finishes but it's not getting called.
I've tried with both, by mentioning receiver class in manifest.xml
file and by using registerReceiver() function.
Could anybody tell what's wrong with that ?

Thanks!

--~--~---------~--~----~------------~-------~--~----~

3. Retrieve Call History

4. calling googlemaps from android

5. call flow through mydroid/hardware/ril/libril/ril.cpp.

6. what is the picture format for Picture.WriteToStream?

7. Call between two emulator