Я создал удаленную службу после примера в этой книге и пытаюсь связать ее с этим действием:
public class TuCanMobileActivity extends Activity {
/** Called when the activity is first created. */
//private HTTPSbrowser mBrowserService;
private HTTPBrowserRemote mBrowserRemoteService;
private Boolean mbound=false;
private ServiceConnection mBrowserRemoteServiceConnection =
new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
try {
mBrowserRemoteService.unregister_course_callback(courseCallback);
} catch (RemoteException e) {}
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mBrowserRemoteService=HTTPBrowserRemote.Stub.asInterface(service);
mbound=true;
try {
mBrowserRemoteService.register_course_callback(courseCallback);
}
catch (RemoteException e) {
// TODO: handle exception
}
}
};
private final IClassesCallback courseCallback =
new IClassesCallback.Stub() {
@Override
public void expressClassesdata(HTTPSResponse ClassesResponse)
throws RemoteException {
Toast.makeText(TuCanMobileActivity.this, "Just works??", Toast.LENGTH_SHORT).show();
final TextView txtLoginName =
(TextView) findViewById(R.id.textView1);
txtLoginName.setText(ClassesResponse.HTMLResponse);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClickSendLogin (final View sfNormal) {
final Intent browserIntent = new Intent(TuCanMobileActivity.this,HTTPBrowserRemoteImpl.class);
this.bindService(browserIntent, mBrowserRemoteServiceConnection, Context.BIND_AUTO_CREATE);
if(mbound==true){
Toast.makeText(TuCanMobileActivity.this, "Service Bound", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(TuCanMobileActivity.this, "Service NOT Bound", Toast.LENGTH_SHORT).show();
}
try {
mBrowserRemoteService.call_course_overview();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*final Intent i = new Intent(this,MainMenu.class);
startActivity(i);*/
unbindService(mBrowserRemoteServiceConnection);
}
}
Но mBrowsserRemoteService имеет значение null (в методе onClickSendLogin)и возвращает исключение NullPointerException, и я не знаю почему?Также кажется, что метод onBind в сервисе никогда не вызывается.Где моя проблема.
Заранее спасибо Тиде