Service
으로 안드로이드 장치에서 실행되는 서버가 있습니다. 사용자가 클라이언트 번호를 입력하고 서비스가 시작되기를 원합니다. 액티비티에서 서비스로 데이터를 전달하는 대신에 이것을 처리하는 더 좋은 방법이 있습니까?서비스를 시작한 후 활동이 중단됩니다.
위의 방법을 사용할 때 클라이언트가 멈추고 응용 프로그램이 강제로 종료되는 것으로 보입니다. 여기
String a = clients.getText().toString();
Bundle bundle = new Bundle();
bundle.putCharSequence("NumberOfClients", a);
Intent intent = new Intent(Manage.this, Server.class);
intent.putExtras(bundle);
Log.d("hi", a);
startService(intent);
그리고 서버입니다 : 다음은 코드가 나는 클라이언트가 응답하여 서버에 연결 버튼을 누르면
@Override
public void onCreate()
{
Thread server = new Thread(new ServerThread());
server.start();
}
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Bundle bundle = new Bundle();
bundle = intent.getExtras();
numberofclients = (String) bundle.getCharSequence("NumberOfClients");
int a = Integer.parseInt(numberofclients);
return a;
}
. 왜 이런 일이 일어나는 걸까요?
로그, 추적 또는 디버깅을 참조하여 무슨 일이 일어 나는지 – Snicolas