I need to instantiate some objects in a separate thread cause i don' t want the UI to get slow. Using AsyncTask i faced the problem of a memory issue: the GC won't deallocate the memory.
So i found the solution declaring AsyncTask as a static inner class. I'm new to android developing so i need your help cause i'm having a NullPointerException. Here is my code:
-static variables because of the inner static class-
public class Wash extends ActionBarActivity {
private static Effetti effect1,effect2,effect3…effect50
private static Effetti[] effects;
.
.
.
-the static inner class-
private static class TaskL extends AsyncTask <Effetti[], Void,Effetti[]> {
@Override
protected Effetti[] doInBackground(Effetti[]... params) {
effects = new Effetti[]{
effects1 = new Effetti(MyApplication.getAppContext(),R.raw.ef1),
effect2=new Effetti(MyApplication.getAppContext(),R.raw.ef2),
effect3 = new Effetti(MyApplication.getAppContext(),R.raw.ef3),
effect4 = new Effetti(MyApplication.getAppContext(),R.raw.ef4),
.
.
.
};
return effects;
}
@Override
protected void onPostExecute(Effetti[] result) {
super.onPostExecute(result);
}
}
The "Effetti" class is a class which contains SoundPool methods for play and stop audio files. Also contains constructors with arguments like context and a resid.
I used MyApplication.getAppContext() trick seen in this post:
Static way to get 'Context' on Android? android
Any suggestion? thaks