0
나는 서비스를 활동에 바인딩하려고 시도한다. 하지만 여기에 ClassCastException 있어요 :ServiceConnectException.onServiceConnected()에서 ClassCastException이 발생했습니다. 바인딩 된 서비스
pos.main.client.ClientBackground_Service.ClientBackground_Binder binder = (ClientBackground_Binder) service;
나는이 예외를 얻을 이유를 정말로 모르겠다. 서비스가 프로세스로 실행 중입니다. 액티비티는이를 가져 와서 사용하려고합니다.
public class ClientMain_Activity extends Activity
{
private boolean m_IsBound = false;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (isMyServiceRunning())
{
Intent intent = new Intent(this, ClientBackground_Service.class);
bindService(intent, m_ServiceConnection, Context.BIND_AUTO_CREATE);
}
}
private ServiceConnection m_ServiceConnection = new ServiceConnection()
{
public void onServiceConnected(ComponentName name, IBinder service)
{
pos.main.client.ClientBackground_Service.ClientBackground_Binder binder = (ClientBackground_Binder) service;
// m_Service = binder.getService();
m_IsBound = true;
}
};
}
서비스 클래스 :
public class ClientBackground_Service extends Service implements
I_ClientBackground_Service
{
private final IBinder m_clientbackground_binding = new ClientBackground_Binder();
public class ClientBackground_Binder extends Binder
{
}
@Override
public IBinder onBind(Intent intent)
{
return m_clientbackground_binding;
}
@Override
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
Log.i(this.getClass().getName(), " ClientBackground_Service started");
}
}
서비스 자체 프로세스로 나쁜 생각입니다 :) – zir