Application lifecycle and onCreate method in the the android sdk
Posted
by Leif Andersen
on Stack Overflow
See other posts from Stack Overflow
or by Leif Andersen
Published on 2010-04-19T20:41:48Z
Indexed on
2010/04/19
20:43 UTC
Read the original article
Hit count: 374
I slapped together a simple test application that has a button, and makes a noise when the user clicks on it. Here are it's method:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button)findViewById(R.id.easy);
b.setOnClickListener(this);
}
public void onClick(View v) {
MediaPlayer mp = MediaPlayer.create(this, R.raw.easy);
mp.start();
while(true) {
if (!mp.isPlaying()) {
mp.release();
break;
}
}
}
My question is, why is onCreate acting like it's in a while loop? I can click on the button whenever, and it makes the sound. I might think it was just a property of listeners, but the Button object wasn't a member variable. I thought that Android would just go through onCreate onse, and proceed onto the next lifecycle method.
Also, I know that my current way of seeing if the sound is playing is crap...I'll get to that later. :)
Thank you.
© Stack Overflow or respective owner