2012-02-29 3 views

답변

2

내 코드입니다. . 스레드를 사용하면 아래 코드를 사용할 수 있습니다.

ProgressBar prg; 
    private void start_thread(final int offer_id) 
    { 
    prg=ProgressDialog.show(this, null, "Getting data...",false,false); 
     new Thread(new Runnable() 
     { public void run() 
     { 
      try { 
       start_prc(); 
       mHandlerSuccess.post(mUpdateSuccess); 
      } catch (Exception e) { 

       mHandlerFail.post(mUpdateFail); 
      } 
     } 
     }).start(); 
    } 
    final Handler mHandlerSuccess= new Handler(); 

    final Runnable mUpdateSuccess = new Runnable() { 
     public void run() { 
      prg.hide(); 
      Toast.makeText(Add_remove_btnsActivity.this, "finished", Toast.LENGTH_LONG).show(); 

     } 
    }; 
    final Handler mHandlerFail= new Handler(); 

    final Runnable mUpdateFail = new Runnable() { 
     public void run() { 
      prg.hide(); 
      Toast.makeText(Add_remove_btnsActivity.this, "failed", Toast.LENGTH_LONG).show(); 

     } 
    }; 
    private void start_prc() 
    { 
     File dir = new File (sdcard.getAbsolutePath() + "/varun"); 
     dir.mkdirs(); 
     File file = new File(dir, "" +var+ ".mp3"); 

    // File file = new File(Environment.getExternalStorageDirectory(), "" +ver+ ".mp3"); 
     FileOutputStream fos; 

     try { 
      fos = new FileOutputStream(file); 
      fos.write(bitmapdata); 
      fos.flush(); 
      fos.close(); 
     } catch (FileNotFoundException e) { 
      // handle exception 
      mHandlerFail.post(mUpdateFail); 
     } catch (IOException e) { 
      // handle exception 
      mHandlerFail.post(mUpdateFail); 
     } 

    } 
+0

도움을 주셔서 감사합니다 – Goofy

0

는 비동기 작업 또는 스레드 클래스를 사용할 수 있습니다 .... AsyncTask 당신이 이것을 달성 할 수를 사용하여 버튼

case R.id.dd: 
File sdcard = Environment.getExternalStorageDirectory(); 
      File dir = new File (sdcard.getAbsolutePath() + "/varun"); 
      dir.mkdirs(); 
      File file = new File(dir, "" +var+ ".mp3"); 

     // File file = new File(Environment.getExternalStorageDirectory(), "" +ver+ ".mp3"); 
      FileOutputStream fos; 

      try { 
       fos = new FileOutputStream(file); 
       fos.write(bitmapdata); 
       fos.flush(); 
       fos.close(); 
      } catch (FileNotFoundException e) { 
       // handle exception 
      } catch (IOException e) { 
       // handle exception 
      } 
+0

감사합니다 그것을 밖으로 시도합니다 – Goofy

관련 문제