如何向服务处理程序发送消息

时间:2017-06-16 17:04:00

标签: android handler

在我的服务中,我创建了获取消息的处理程序,并对消息做了一些工作。

   class ClientHandler extends Handler {

    @Override
    public void handleMessage(Message msg) {

        switch (msg.what) {
            case PUBLISH:

                connection.makeRequest(msg);
        }
        super.handleMessage(msg);
    }
}

               switch (msg.what) {

                case PUBLISH:{

                    boolean status = false;
                    Bundle b = msg.getData();
                    if (b != null) {
                        CharSequence cs = b.getCharSequence(TOPIC);
                        if (cs != null) {
                            String topic = cs.toString().trim();
                            if (topic.isEmpty() == false) {
                                cs = b.getCharSequence(MESSAGE);
                                if (cs != null) {
                                    String message = cs.toString().trim();
                                    if (message.isEmpty() == false) {
                                        status = publish(topic, message);
                                    }

在我的活动中,我有编辑文本,我想将setText.tostring作为消息发送到我的服务我不想在我的活动中显示任何内容然后我不想绑定它。如何在没有活页夹的情况下向我的服务处理程序发送一条消息?我不想使用活页夹

0 个答案:

没有答案
相关问题