5

在我的活动“A”中,我使用计时器和媒体播放器播放音频。我的应用程序有一个设置活动,比如活动“B”,用于选择音频播放模式。我正在使用 startActivityForResult()并从活动 B 发送一个 resultCode。问题是活动 B 需要太多时间才能完成。因为 A 中的音频在 B 完全结束之前开始。这个怎么处理???

我的活动 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;
            }
        }
    }
4

1 回答 1

0

它将,因为您正在 UI 线程上进行位图处理,您应该使用不同的线程来完成此类工作,请阅读高效显示位图

于 2013-08-29T06:27:17.897 回答