
希望你能问得更详细点。Tornado是一个跟Nodejs差不多的轻量级>
>
国内也有类似的解决方案,比如百度云推送:
>
这些推送服务的大概流程如下:
你的云端程序(比如Tornado)形成一个通知;
你的云端程序向推送服务发送一个请求;
推送服务向它在客户端的代理转发你的请求;
客户端代理在安卓上广播这个请求,你的移动app得到这个广播;
你的移动app可以在通知中心形成一个intent,或是启动你的后台服务来处理这个请求。
1 从Service继承一个类。2 创建startService()方法。
3 创建endService()方法 重载onCreate方法和onDestroy方法,并在这两个方法里面来调用startService以及endService。
4 在startService中,通过getSystemService方法获取ContextLOCATION_SERVICE。
5 基于LocationListener实现一个新类。默认将重载四个方法onLocationChanged、onProviderDisabled、onProviderEnabled、onStatusChanged。对于onLocationChanged方法是我们更新最新的GPS数据的方法。一般我们的 *** 作都只需要在这里进行处理。
6 调用LocationManager的requestLocationUpdates方法,来定期触发获取GPS数据即可。在onLocationChanged函数里面可以实现我们对得到的经纬度的最终 *** 作。
7 最后在我们的Activity里面通过按钮来启动Service,停止Service。
示意代码如下:
package comoffbyegpsservice;
import androidappService;
import androidcontentContext;
import androidcontentIntent;
import androidlocationLocationListener;
import androidlocationLocationManager;
import androidosBinder;
import androidosIBinder;
import androidutilLog;
public class GPSService extends Service {
// 2000ms
private static final long minTime = 2000;
// 最小变更距离10m
private static final float minDistance = 10;
String tag = thistoString();
private LocationManager locationManager;
private LocationListener locationListener;
private final IBinder mBinder = new GPSServiceBinder();
public void startService() {
locationManager = (LocationManager) getSystemService(ContextLOCATION_SERVICE);
locationListener = new GPSServiceListener();
locationManagerrequestLocationUpdates(LocationManagerGPS_PROVIDER, minTime, minDistance,
locationListener);
}
public void endService() {
if (locationManager != null && locationListener != null) {
locationManagerremoveUpdates(locationListener);
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return mBinder;
}一般MySQL都不由APP进行直接的远程连接,而是交由后台服务器进行封装处理的。
举个例子。APP访问--》后台PHP服务器--》PHP访问本地MySQL数据库--》PHP返回查询给APP
所以,一般的APP分为两部分,APP前端开发,PHP后台开发
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)