0
서비스에서 MediaPlayer를 재생하는 활동을 시작했으나 잘 시작되지만 즉시 onPause 및 leave를 호출합니다. 하지만 Activity에 onPause() 메서드를 추가하지 않으면 Mediaplayer가 잘 재생되고보기가 정확합니다.서비스에서 시작한 활동이 너무 빨리 onPause를 호출 중입니다.
서비스 :
import android.content.Intent;
import android.util.Log;
public class ReminderService extends WakeReminderIntentService {
public ReminderService() {
super("ReminderService");
}
@Override
void doReminderWork(Intent intent) {
Log.d("ReminderService", "Doing work.");
Intent dialogIntent = new Intent(getBaseContext(), TestRec.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(dialogIntent);
}
}
TestRec.class :
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.view.Window;
import android.view.WindowManager;
public class TestRec extends Activity {
MediaPlayer mp;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
);
mp = MediaPlayer.create(this, R.raw.music);
mp.start();
}
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mp.stop();
finish();
}
}