0
Я пытаюсь привязать службу к активности. Но я получил ClassCastException здесь:ClassCastException в ServiceConnection.onServiceConnected(). Связанные службы
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