gpt4 book ai didi

android - Activity 完成得太慢

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:27:08 24 4
gpt4 key购买 nike

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

我的 Activity B 调用代码是:

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

我的 Activity 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();
}
}

和 Activity A 中的 OnActivityResult 是:

@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;
}
}
}

最佳答案

它会的,因为你在 UI 线程上进行位图处理,你应该为这种工作使用不同的线程,阅读 Displaying Bitmaps Efficiently

关于android - Activity 完成得太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18503592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com