什么是intent的action?
/** * Create an intent with a given action. All other fields (data, type, * class) are null. Note that the action <em>must</em> be in a * namespace because Intents are used globally in the system -- for * example the system VIEW action is android.intent.action.VIEW; an * application's custom action would be something like * com.google.app.myapp.CUSTOM_ACTION. * * @param action The Intent action, such as ACTION_VIEW. */ public Intent(String action) { setAction(action); }
client 侧调用service, 进程间的对象传输使用Bundle
Intent intent = new Intent("action_upload_subsys_report");
ComponentName component = new ComponentName("com.xxx", "com.xxx.service.yyyService"); intent.setComponent(component); Bundle bundle = new Bundle(); bundle.putString("subsys", subsys); bundle.putString("keyPattern", keyPattern); bundle.putString("type", type); intent.putExtras(bundle); startServiceAsUser(intent, UserHandle.CURRENT);
server侧:
onStartCommand {
if (intent.getAction().equalsIgnoreCase(ACTION_UPLOAD_SUBSYS_REPORT)) {if (intent.getExtra() != null) {
sendMessages(HANDLE_REPORT, intent.getExtras());
}
}
}
handleMessage(Message msg) {
case HANDLE_REPORT:
Bundle bundle = (Bundle) msg.obj;
String time = bundle.getString("keyPattern");
String type = bundle.getString("type");
}