Omar Hassan
Omar Hassan

Reputation: 3

what is the mistake of this code?

why is raw folder in code have a red line although i have this folder !!!! ?

enter image description here

what is the wrong ?

package com.example.second;

public class omar extends Activity {

MediaPlayer song;
@Override
protected void onCreate(Bundle omar) {
    // TODO Auto-generated method stub
    super.onCreate(omar);
    setContentView(R.layout.omar);

    song = MediaPlayer.create(omar.this, R.raw.one);
    song.start();


    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent open = new Intent("android.intent.action.MAIN");
                startActivity(open);
            }

        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();

    song.release();
    finish();
}


}

and what is the last method mean ?

    @Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();

    song.release();
    finish();
}

Upvotes: 0

Views: 75

Answers (4)

magmike
magmike

Reputation: 473

When the activity is being paused it is a good strategy to release the resources used by the MediaPlayer object.That's what release() does here.

finish() just finishes the activity

Check these out

http://developer.android.com/reference/android/media/MediaPlayer.html#release()

http://developer.android.com/reference/android/app/Activity.html#finish()

Upvotes: 0

EdmDroid
EdmDroid

Reputation: 1360

You have res/layout/raw. It's not right. It's res/raw

Also follow the link given to you by rup35h.

Upvotes: 0

rupesh
rupesh

Reputation: 2891

raw should be outside from the layout folder and inside res Please prefer this.

http://developer.android.com/guide/topics/resources/providing-resources.html

Upvotes: 3

Bart Kiers
Bart Kiers

Reputation: 170158

You have res/layout/raw, while it should be res/raw I believe.

Upvotes: 4

Related Questions