启动service方法

来源:互联网 发布:51自学网单片机 编辑:程序博客网 时间:2024/06/08 15:01
启动端        final Intent implicitIntent = new Intent();        final ComponentName component = new ComponentName(packageName,                className);        Intent explicitIntent = new Intent(implicitIntent);        explicitIntent.setAction(CMD_ACTION);        explicitIntent.putExtra(KEY_TYPE, keyType);        explicitIntent.putExtra(KEY_PARAMTER, parms);        explicitIntent.setComponent(component);        context.startService(explicitIntent);接收端口  @Override    public int onStartCommand(Intent intent, int flags, int startId) {        if (intent != null) {            String action = intent.getAction();            Logger.i(TAG, "onStartCommand::action : " + action);            if (ServiceConstant.CMD_ACTION.equals(action)) {                handleIntent(intent);            }        }        return START_STICKY;    }private void handleIntent(Intent intent) {        int keyType = intent.getIntExtra(ServiceConstant.KEY_TYPE, -1);        if (keyType == VoiceConstant.OPEN_ECAR) {            ECarMgr.getInstance(this).initEcar();        }        String[] data = intent.getStringArrayExtra(ServiceConstant.KEY_PARAMTER);    }

0 0
原创粉丝点击