为什么这会让我的屏幕消失并使我的手机崩溃?

时间:2012-08-22 05:07:01

标签: android crash android-activity android-mediaplayer android-lifecycle

当我删除onResume()方法时,程序工作正常,但当我把它留在程序中正常启动音乐播放但我的屏幕上没有显示任何内容,然后当我尝试退出时冻结并采取电话从冻结中走出来的一分钟。这个onResume()方法有什么问题?你需要看到我的所有代码吗?为什么会这样?

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    int spot = settings.getInt("point", 0);
    try {
        music.get(track).prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    music.get(track).seekTo(spot);
    music.get(track).start();
}

这是onCreate()

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    song0 = MediaPlayer
            .create(TheParty0Activity.this, R.raw.blacksunempire);
    song1 = MediaPlayer.create(TheParty0Activity.this, R.raw.blueskies);
    song2 = MediaPlayer.create(TheParty0Activity.this, R.raw.fuckingnoise);

    music.add(song0);
    music.add(song1);
    music.add(song2);

    music.get(track).start();

    // box = (TextView) findViewById(R.id.editText1);
    // play = (Button) findViewById(R.id.button0);
    next = (Button) findViewById(R.id.button1);
    // extra = (Button) findViewById(R.id.button2);

    next.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            music.get(track).stop();
            track++;
            if (track == 3) {
                for (int i = 0; i < 3; i++) {
                    try {
                        music.get(i).prepare();
                    } catch (IllegalStateException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    music.get(i).seekTo(0);
                }
                track = 0;
            }
            music.get(track).start();
        }
    });
    extra.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            Intent ourIntent = new Intent(TheParty0Activity.this, Sam.class);
            startActivity(ourIntent);
        }
    });


}

1 个答案:

答案 0 :(得分:0)

没关系这些方法都不是问题