2013-08-29 110 views
5

在我的活動'A'中,我使用計時器和媒體播放器播放音頻。我的應用有一個設置活動說活動「B」,用於選擇音頻播放模式。我正在使用startActivityForResult(),並從活動B發送resultCode。問題是活動B需要花費太多時間才能完成。因爲在B完成之前,A中的音頻開始播放。如何處理這個?活動結束太慢

我的活動B callig代碼:

Intent intent = new Intent(context, Setting.class); 
     startActivityForResult(intent, Cover.SETTING_REQ); 

和我的活動B已經下面的代碼:

public class Setting extends Activity { 
    Context context; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.settings); 
     context = this; 
     final RelativeLayout layout = (RelativeLayout) findViewById(R.id.setting_layout); 
     Display display = getWindowManager().getDefaultDisplay(); 
     final int width = display.getWidth(); 
     final int height = display.getHeight(); 
     int[] modes = { R.drawable.settingspageiphone, R.drawable.readtome, 
       R.drawable.readwithpause, R.drawable.icanreadit }; 
     Bitmap bm = BitmapLib.prepairBitmap(context, modes[Read.mode], width, 
       height); 
     layout.setBackgroundDrawable(new BitmapDrawable(bm)); 
     layout.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       // TODO Auto-generated method stub 
       double x = event.getX(); 
       double y = event.getY(); 
       double H = layout.getHeight(); 
       double W = layout.getWidth(); 
       if (H * 320 > W * 480) { 
        H = W * 480/320; 
        y = y - (layout.getHeight() - H)/2; 
       } else { 
        W = H * 320/480; 
        x = x - (layout.getWidth() - W)/2; 
       } 
       x = x/W * 320; 
       y = y/H * 480; 
       if (x > 50 && x < 270) { 
        if (y > 150 && y < 190) { 
         // read to me 
         Bitmap bm = BitmapLib.prepairBitmap(context, 
           R.drawable.readtome, width, height); 
         layout.setBackgroundDrawable(new BitmapDrawable(bm)); 
         Read.mode=1; 
         setResult(1); 
         finish(); 
         return false; 
        } 
        if (y > 230 && y < 270) { 
         // read with pause 
         Bitmap bm = BitmapLib.prepairBitmap(context, 
           R.drawable.readwithpause, width, height); 
         layout.setBackgroundDrawable(new BitmapDrawable(bm)); 
         Read.mode=2; 
         setResult(2); 
         finish(); 
         return false; 
        } 
        if (y > 320 && y < 360) { 
         // i can read it 
         Bitmap bm = BitmapLib.prepairBitmap(context, 
           R.drawable.icanreadit, width, height); 
         layout.setBackgroundDrawable(new BitmapDrawable(bm)); 
         Read.mode=3; 
         setResult(3); 
         finish(); 
         return false; 
        } 
        /*if (y > 430 && y < 470) { 
         setResult(-1); 
         finish(); 
         return false; 
        }*/ 
       } 
       return false; 
      } 
     }); 
    } 

    public void cancle(View v) 
    { 
     setResult(-1); 
     finish(); 
    } 
} 

OnActivityResult在活動A是:

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     // TODO Auto-generated method stub 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == Cover.SETTING_REQ) { 
      if (resultCode != -1) { 
       Cover.MODE = resultCode; 
       update = true; 
      } 
     } 
    } 

回答

0

會,因爲你正在UI線程上進行位圖處理,所以你應該爲這種類型使用不同的線程f工作,閱讀Displaying Bitmaps Efficiently

+0

但我也有另外兩個沒有任何位圖相關處理的活動,但我仍然得到同樣的問題。 –