I believe there is a conn.disconnect() and as you mentioned it is
always good to close() the inputstream.

I assume this operation occurs in another thread instead of the UI
thread. Take a look at the asynctask class offered with 1.5. You can
call cancel on the thread and raise the onCancelled() event or check
for isCancelled() boolean in your loop.

-dc

On Jul 1, 4:09 am, Brad Chou <[email protected]> wrote:
> I open a connect like this:
>
> URL mUrl = new URL("http://www.abc.com/4MB.mp3";);
> URLConnection conn = mUrl.openConnection();
> conn.connect();
> InputStream is = conn.getInputStream();
>
> FileOutputStream fos = new FileOutputStream(tmpFile);
> byte[] readBody = new byte[4096];
> do {
>     int readBytes = is.read(readBody);
>     if (readBytes <= 0) {
>         break;
>     }
>     fos.write(readBody, 0, readBytes);
>
> }while(true);
>
> I have two question
> (1) How to cancel the connection when conn.connect() is executed ? I
> can not find any useful API from  
> http://developer.android.com/reference/java/net/URLConnection.html
> (2) When user cancel this activity, I use is.close() to cancel the
> is.read(). Is that a good way to cancel InputStream ? and how to handle
> (cancel) the conn this moment ?
>
> Best Regards,
> Brad
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to