This is because field logoMusic
is null in the onPause. Try adding volatile
modifier to it. Also the code:
Thread logoTimer = new Thread() {
public void run() {
try{
sleep(5000);
Intent menuIntent = new Intent("com.jonald.mazeonmath.MENU");
startActivity(menuIntent);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
doesn't seem right, as I think you should't start new activity from a background thread. Use AsyncTask
's onPostExecute [1] for that. Then you shouldn't need the volatile
keyword.
1 - http://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result)
EDIT: Please try to replace the code above (starting with Thread logoTimer
and ending with logoTimer.start();
) with the following code:
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
Intent menuIntent = new Intent("com.jonald.mazeonmath.MENU");
startActivity(menuIntent);
finish();
}
}.execute();
And then tell me if this will work.
EDIT 2: It was hidden in the plain sight all the time. Under the line with setContentView
, you're declaring method variable, instead setting the field. Remove the MediaPlayer
and leave just logoMusic = MediaPlayer.create(....)
and it should work.