서비스를 시작하는건 정상적으로 작동을 합니다.
Button disconnection = findViewById(R.id.disconnection);
disconnection.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Toast.makeText(getApplicationContext(),"Service 중지", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FrontMenu.this, SocketService.class);
stopService(intent);
}
});
이러한 버튼을 만들고 서비스에서는 다음 코드를 실행하는걸로 알고 있습니다.
public void onDestory() {
thread.stopForever();
thread = null; //
}
다음 Thread단의 stopForever() 입니다.
public void stopForever() {
synchronized (this){
this.isRun = false;
}
}
public void run(){
while(isRun){
handler.sendEmptyMessage(0); //쓰레드에 있는 핸들러에게 메세지를 보냄
try{
Thread.sleep(5000);
}catch (Exception e){
}
}
}
정말 열심히 찾아보다가 안되서 이렇게 질문을 올립니다.. 어떤 부분에서 문제가 생기는걸까요 ..