I'm currently working on a small Java/Android app which should download a remote binary file and save it locally. This app should run on an Android device, more precisely a Samsung Galaxy S GTI9000. I'm currently using Eclipse SDK Version 3.7.0. Below is the code causing the problem:

Java Code:
public void downloadRemoteSceneFile()
    {
    	//TODO: pass scene file name as a parameter
    	String strSceneFileName = "http://www.mysite.com/myfolder/myremotebinaryfile.dat" ;
    	
    	int count;
        try
        {
        	URL url = new URL(strSceneFileName);
            if(url == null)
            	return ;
            
            //Remember to import java.net.HttpURLConnection ; at file begin
            //if you want to use HttpURLConnection instead of URLConnection
            HttpURLConnection conexion = (HttpURLConnection)url.openConnection() ;
            
            if(conexion == null)
            	return ;
            
            //Use these two instructions if using HttpURLConnection instead of URLConnection
            conexion.setRequestMethod("GET") ;
            //conexion.setDoOutput(true) ;
            
            //conexion.setDoInput(true) ;
            //conexion.setDoOutput(false) ;
            
            conexion.connect(); //THIS INSTRUCTION LEADS TO A CRASH !!!!!!
            // this will be useful so that you can show a tipical 0-100% progress bar
            int lenghtOfFile = conexion.getContentLength() ;
            
            // downlod the file
            InputStream input = new BufferedInputStream(url.openStream());
            OutputStream output = new FileOutputStream("/sdcard/somewhere/nameofthefile.ext");
            
            byte data[] = new byte[1024];
            
            while ((count = input.read(data, 0, 1024)) != -1)
            {
                total += count;
                 //publishing the progress....
                publishProgress((int)(total*100/lenghtOfFile));
                updateRemoteFileDownloadProgressBar((float)total / (float)lenghtOfFile) ;
                output.write(data, 0, count);
            }
            
            output.flush();
            output.close();
            input.close();
        }
        catch (Exception e)
        {
        	Log.v("TEST", "inside catch(Exception e)") ;
        	System.out.println("!!!!!!!!! System.out.println - inside catch(Exception e) !!!!!!!!!") ;
        }
        finally
        {
        	Log.v("TEST", "inside finally") ;
        }
    }
As one of the above code comments says (//THIS INSTRUCTION LEADS TO A CRASH!), the problem comes when the instruction conexion.connect() is executed: at this point program very often crashes, although this happens quite often but not always (and I cannot understand why…) and the phone's logcat shows the message: W/InputManagerService (2251): Got RemoteException sending setActive(false) notification to pid 3817 uid 10091. I tried to use conexion.setDoInput(true) but problem persists.
Also please note that I have already added inside AndroidManifest.xml the line with the permission to access the Internet (<uses-permission android:name="android.permission.INTERNET" />).

Anyone can help?
Thanks in advance!