通过管理服务到mysql的连接 [英] Managing a connection to the mysql through a service

查看:96
本文介绍了通过管理服务到mysql的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我产生了手机定位服务。
我想这个字符串发送到我的分贝,但它通过服务是不可能的,因为我得到主线程异常的连接。
我应该怎么办呢?我想发送位置每隔x时间(大概一分钟)。

I got a service that generate the phone location. I would like to send this string into my db but it's impossible through the service since I get a connection on main thread exception. How should I do that?I would like to send the location every x time(probably a min).

我知道如何连接到MySQL数据库和各地,但我只是不知道如何管理这个系统,谢谢。

I know how to connect to a mysql db and all around but I just don't know how to manage this system, thanks.

推荐答案

这无关的服务本身。

的问题是,您的操作正在UI线程,这是有效地从做别的停止在UI上执行

The problem is that your operations are being executed on the UI thread, which is effectively stopping the UI from doing anything else.

这是调用服务的生命周期回调的线程( onStartCommand() onBind()等)是UI线程。
你只需要启动它的遗嘱执行人服务,或者一个新的线程,或取决于你实现什么的 IntentService 可能是一个方便的类中使用。

The thread that calls the service life-cycle callbacks (onStartCommand(), onBind(), etc) is the UI thread. You just have to fire it on an executor service, or a new thread, or depending on what you're implementing a IntentService might be a handy class to use.

这篇关于通过管理服务到mysql的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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