我有一个活动,这是splash activity
,我想在其中加载 2 首音乐,加载完成后我想开始我的欢迎页面,不幸的是我做错了。
即使我得到了log
加载完成时制作的内容,但是当没有加载 2 首音乐时我也得到了日志..
日志
Loaded 1 true
Loaded 2 true
1 not two
2 not two
代码
package com.Syriatel.EatTel;
import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Load1().execute(1);
new Load2().execute(2);
}
public int soundID, soundID2;
private SoundPool soundPool1, soundPool2;
boolean isLoad1, isLoad2;
class Load2 extends AsyncTask<Integer, Integer, Integer> {
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
if (isLoad1 && isLoad2) {
Intent intent = new Intent(Splash.this, Welcome.class);
finish();
startActivity(intent);
}else{
Log.e("2", "not two");
}
}
@Override
protected Integer doInBackground(Integer... params) {
soundPool2 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundPool2.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
isLoad2 = true;
Log.e("Loaded 2", "true");
}
});
soundID2 = soundPool2.load(getApplicationContext(), R.raw.select, 1);
return 1;
}
}
class Load1 extends AsyncTask<Integer, Integer, Integer> {
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
if (isLoad1 && isLoad2) {
Intent intent = new Intent(Splash.this, Welcome.class);
finish();
startActivity(intent);
}else{
Log.e("1", "not two");
}
}
@Override
protected Integer doInBackground(Integer... params) {
soundPool1 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundPool1.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
isLoad1 = true;
Log.e("Loaded 1", "true");
}
});
soundID = soundPool1.load(getApplicationContext(), R.raw.thip, 1);
return 1;
}
}
}