안드로이드 개발 질문/답변
(글 수 45,052)
MediaPlayer mp = MediaPlayer.create(context, R.raw.img);
mp.start();
이렇게 쓰는데 context 부분에 에러가 생깁니다.
조언부탁드립니다.
mp.start();
이렇게 쓰는데 context 부분에 에러가 생깁니다.
조언부탁드립니다.
2011.01.05 05:13:25
Activity 를 상속받은 상태에서라면
일반적으로 this 를
MediaPlayer.create( this, R.raw.img );
와 같이 해주시면 될것이고요.
또한 context 대신, getBaseContext() 를 넣어주셔도 됩니다.
(경우에 따라서는 getApplicationContext() 를 넣어주시면 됩니다)
context 가 무엇인지 한번 확인해보고 넘어가면 도움이 될것 같습니다.
안드로이드 시스템에서 activity를 포함한 class 및 resource 등에 접근할때 필요합니다.
Context의 가장 간략한 정의는 다음과 같습니다.
Interface to global information about an application environment.



