Reputation: 19
How can I start the thread in this code? Where and how to start the thread activity because my application stops when it goes to this section of code.
public class Lesson_p extends Activity implements OnClickListener {
MediaPlayer p, p_sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lesson_p);
p = MediaPlayer.create(this, R.raw.p);
p_sound = MediaPlayer.create(this, R.raw.p_sound);
View p = findViewById(R.id.imageButton_p);
p.setOnClickListener((OnClickListener)this);
View p_sound = findViewById(R.id.imageButton_pp);
p_sound.setOnClickListener((OnClickListener)this);
Button back = (Button) findViewById(R.id.button_bckp);
back.setOnClickListener((OnClickListener)this);
Button next = (Button) findViewById(R.id.button_nxtp);
next.setOnClickListener((OnClickListener)this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.imageButton_p:
p.start();
break;
case R.id.imageButton_pp:
p_sound.start();
break;
case R.id.button_bckp:
Intent back = new Intent(this, Example_n.class);
startActivity(back);
break;
case R.id.button_nxtp:
Intent next = new Intent(this, Example_p.class);
startActivity(next);
break;
}
}
//@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
p.release();
p_sound.release();
}
}
Upvotes: 0
Views: 68
Reputation: 3271
You said it stops in the button_nxtp
function (which isn't a function, it's just a certain case in a switch).
Looks like you're creating and starting an Intent for an Example_p
activity. Step through the onCreate()
and onStart()
methods of your Example_p
class using the debugger and you should be able to find your error.
Upvotes: 0