Este es mi código:Android, AsyncTask, ¿comprobar el estado?
En onCreate:
new LoadMusicInBackground().execute();
Luego, hacia el final de mi clase principal que tengo este código
/** Helper class to load all the music in the background. */
class LoadMusicInBackground extends AsyncTask<Void, String, Void> {
@Override
protected Void doInBackground(Void... unused) {
soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(A1,
soundPool.load(GameScreen_bugfix.this, R.raw.a, 1));
soundPoolMap.put(A3,
soundPool.load(GameScreen_bugfix.this, R.raw.b, 1));
soundPoolMap.put(A5,
soundPool.load(GameScreen_bugfix.this, R.raw.c_s, 1));
soundPoolMap.put(A6,
soundPool.load(GameScreen_bugfix.this, R.raw.d, 1));
soundPoolMap.put(A8,
soundPool.load(GameScreen_bugfix.this, R.raw.e, 1));
soundPoolMap.put(A10,
soundPool.load(GameScreen_bugfix.this, R.raw.f_s, 1));
soundPoolMap.put(A12,
soundPool.load(GameScreen_bugfix.this, R.raw.g_s, 1));
soundPoolMap.put(wrong,
soundPool.load(GameScreen_bugfix.this, R.raw.wrong2, 1));
publishProgress("");
Log.v("SOUNDPOOL", "" + soundPoolMap);
return (null);
}
@Override
protected void onProgressUpdate(String... item) {
// text1.setText(item[0]);
}
@Override
protected void onPostExecute(Void unused) {
//Toast.makeText(GameScreen_bugfix.this, "music loaded!", Toast.LENGTH_SHORT).show();
}
}
Si la música no ha cargado Me estoy haciendo una Excepción nullpointer, mirando los documentos veo que hay un getStatus() pero he intentado algo como esto:
music_load_status=LoadMusicInBackground.getStatus()
y eso no funciona :( ¿Cómo puedo verificar si la tarea de fondo está completa y la música cargada?
Gracias!
Ryan
Gracias! Lo verificará! – Ryan
Para aclarar: FINISHED es el estado DESPUÉS de llamar a PostExecute. Si comprueba el estado en onPostExecute, el estado será RUNNING – user123321
, entonces, ¿por qué devuelve RUNNING en postexcute, es sorprendente – Sameer