안드로이드 개발 질문/답변
(글 수 45,052)
우선 제가 짠 코드가 이런데요.
서비스가 실행이 되면 다른 버튼도 안 눌러지고 폰이 뻗어 버려요 제 생각으로는 while문에 어느 정도 딜레이 되는 게 없어서 그런 것 같은데 맞나요? 만약 그렇다면 안드로이드는 멀티 태스킹이 되는 데 한 스레드가 계속 돌아가도 되는 거 아닌가요? 초보자의 질문 입니다
public class LoginService extends Service{
boolean isStart=true;
public void onCreate(){
super.onCreate();
}
public void onDestroy(){
super.onDestroy();
Toast.makeText(this, "서비스 종료", Toast.LENGTH_LONG).show();
isStart=false;
}
public int onStartCommand(Intent intent, int flags, int startId){
super.onStartCommand(intent, flags, startId);
LoginThread thread = new LoginThread();
thread.start();
Toast.makeText(this, "서비스 시작", Toast.LENGTH_LONG).show();
return START_STICKY;
}
public IBinder onBind(Intent intent) {
return null;
}
class LoginThread extends Thread{
public void run(){
while(isStart){
connection.connect();
connection.login("king","1");
}
}
}
}
서비스가 실행이 되면 다른 버튼도 안 눌러지고 폰이 뻗어 버려요 제 생각으로는 while문에 어느 정도 딜레이 되는 게 없어서 그런 것 같은데 맞나요? 만약 그렇다면 안드로이드는 멀티 태스킹이 되는 데 한 스레드가 계속 돌아가도 되는 거 아닌가요? 초보자의 질문 입니다
public class LoginService extends Service{
boolean isStart=true;
public void onCreate(){
super.onCreate();
}
public void onDestroy(){
super.onDestroy();
Toast.makeText(this, "서비스 종료", Toast.LENGTH_LONG).show();
isStart=false;
}
public int onStartCommand(Intent intent, int flags, int startId){
super.onStartCommand(intent, flags, startId);
LoginThread thread = new LoginThread();
thread.start();
Toast.makeText(this, "서비스 시작", Toast.LENGTH_LONG).show();
return START_STICKY;
}
public IBinder onBind(Intent intent) {
return null;
}
class LoginThread extends Thread{
public void run(){
while(isStart){
connection.connect();
connection.login("king","1");
}
}
}
}



