I have an activity, this is the splash activity
, I want to load 2 music in it and when the loading is finish I want to start my welcome page, unfortunately I made something wrong.
Even though I got the log
which I made when the load is complete , but I also got the log when the 2 music are not loaded..
Log
Loaded 1 true
Loaded 2 true
1 not two
2 not two
code
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;
}
}
}