Android 实例展现如何不同程序间的Serivce调用
2010-09-15 00:10:00 来源:WEB开发网Bundle b = new Bundle();
b.putString("pushdata1", ev1.getText().toString());
b.putString("pushdata2", ev2.getText().toString());
// demoService.putExtras(b);
demoService2.putExtras(b);
startService(demoService2);
// bindService(demoService2, sc, Context.BIND_AUTO_CREATE);
// startService(demoService2);
// startService(demoService2);
}
});
bstop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Intent demoService = new Intent(ServiceActivity.this,
// DemoService.class);
Intent demoService2 = new Intent("com.shinestudio.demo.demoservice");
// unbindService(sc);
// stopService(demoService2);
// if(sc!=null)
// unbindService(sc);
// stopService(demoService2);
// unbindService(sc);
stopService(demoService2);
}
});
tv = (TextView) findViewById(R.id.tv);
bget = (Button) findViewById(R.id.b_get);
bget.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (dsb != null) {
try {
tv.setText(dsb.getPushString());
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
});
bset = (Button) findViewById(R.id.b_set);
bset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (dsb != null) {
try {
dsb.setPushString(ev2.getText().toString());
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
});
}
}
IDemoServiceBinder.aidl
更多精彩
赞助商链接