안녕하세요 ~



음악 스트리밍 기능을 추가하려고 하고 있습니다.


현재 구성은


MainActivity - web

PlaybackActivity - 플레이어 부분 (UI)

PlaybackService - 실제 음악 재생 부분


기반은 웹앱이고, javaScript로 playbackActivity를 실행해서, 서비스가 실행되는 구조입니다.



현재 문제가 Notification에 등록된 playbackActivity관련입니다. 


Main (web) -> playbackactivity -> back -> back -> notification탭 -> playbackActivity 진입시에


서비스가 다시 시작되고 (음악도 재시작), 백버튼을 눌러보면 바로 홈으로 가게됩니다...


제가 원하는것은 어떤 사이클에서도 playActivity에선 플레이 상태를 표기하고 백했을때 원래 Main(web) 화면이 나왔으면 합니다.



// play Method in Service.java


Notification notification = new Notification(resId, text, System.currentTimeMillis());

notification.flags |= Notification.FLAG_ONGOING_EVENT;


Intent toLaunch = new Intent(PlaybackService.this, PlaybackActivity.class);

toLaunch.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);


PendingIntent intentBack = PendingIntent.getActivity(this, 0, toLaunch, 0);

notification.setLatestEventInfo(PlaybackService.this, getText(R.string.app_name), text, intentBack);


startForeground(PLAYBACKSERVICE_STATUS, notification);


pause시엔, stopForgeground(true); 처리해줬습니다.


// onStart Method in Activity.java


Activity realActivity = context.getParent();

if (realActivity == null) {

realActivity = context;

}


ContextWrapper cw = new ContextWrapper(realActivity);

cw.startService(new Intent(cw, PlaybackService.class));


// onStop Method in Activity.java


ContextWrapper cw;

cw.unbindService(sb);

mService = null;


대략의 코드는 이 정도입니다.


기본 뮤직 플레이어 소스를 받아서 참고하고 있지만, 생각보다 어렵네요..


조언 부탁드립니다 ~