如果我按下主页按钮而未播放音频。该应用程序崩溃,但是当我播放音频并按下主页按钮时,它可以正常工作。 这里是我的代码:如果在没有播放音频的情况下按下主页按钮,则应用程序崩溃
@Override
protected void onPause()
{
Context context = getApplicationContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
if (!taskInfo.isEmpty()) {
ComponentName topActivity = taskInfo.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
play.pause();
but19.setBackgroundResource(R.drawable.play);
}
}
super.onPause();
}
@Override
public void onBackPressed(){
if(play!=null && (play.isPlaying())){
if(play.isPlaying())
play.stop();
play.release();
}
super.onBackPressed();
}
添加您的崩溃日志。 –