In my activity 'A' I am using timer and media player to play audio. My app is having a Setting activity say activity 'B', for the selection of audio playing modes. I am using startActivityForResult()
and sends a resultCode from activity B. Problem is that activity B is taking too much time to finish. as the audio in A start before the B finishes completely. how to handle this???
my activity B callig code is:
Intent intent = new Intent(context, Setting.class);
startActivityForResult(intent, Cover.SETTING_REQ);
and my activity B has following code:
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();
}
}
and OnActivityResult
in activity A is:
@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;
}
}
}
It will, because you are doing the bitmap processing on the UI thread, you should use a different thread for this kind of work, read Displaying Bitmaps Efficiently