Android的磨损不启动线程 [英] Android wear doesn't start thread

查看:153
本文介绍了Android的磨损不启动线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个应用程序与我的团队的机器人汽车,让驾驶它通过移动设备进行控制。它完美我的手机上,但现在,我已经移植应用程序到Android Wear,线程,让我连接到我的树莓派的服务器无法正常工作。有没有办法让这个线程工作?

I'm building an application with my team for a robot car to let it drive controlled by a mobile device. It works perfectly on my phone, but now that I've ported the app to Android Wear, the thread that lets me connect to a server on my Raspberry Pi doesn't work. Is there a way to get this thread working?

code:

public class SocketConnect {

static DataOutputStream dOut;
static Socket socket;

public static void connect() {
    System.out.println("Got to Connect");
    new Thread() {
        public void run() {

            try {

                socket = new Socket("192.168.2.9", 8899);
                System.out.println("Trying at 2.9");
                dOut = new DataOutputStream(socket.getOutputStream());
            } catch (IOException e) {

                e.printStackTrace();
            }

        }

    }.start();

}
....further code

logcat的错误: http://pastebin.com/0BtF27p8
(无法得到它的格式编辑器好听)

Logcat error: http://pastebin.com/0BtF27p8 (couldn't get it to format nice in the editor)

推荐答案

两个问题你的方法:


  1. NetworkOnMainThreadException - 你不能做主(UI),网络运营线程上Android 4.0以上版本的设备

  2. Android Wear设备不能直接连接到的任何互联网地址 - 您必须使用的可穿戴数据层将信息发送到手机上的应用程序,并将它连接/信息传递到服务器

  1. NetworkOnMainThreadException - you can't do network operations on the main (UI) thread on Android 4.0+ devices
  2. Android Wear devices cannot directly connect to any internet address - you have to use the Wearable Data Layer to send information to the phone app and have it connect/pass information to a server

在很多情况下,包括你想要控制机器人车做什么,你可能想使用的邮件从监视传输一个轻量级的命令到您的手机应用程序。

In many cases, including what you'd want to do for controlling a robot car, you'd probably want to use messages to transfer a lightweight command from the Watch to your phone app.

这篇关于Android的磨损不启动线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆