方法调用不在服务类android中工作

时间:2016-03-14 10:11:37

标签: methods call

嗨,这里是我的代码我想在get()中调用insert(纬度,经度),但它对我不起作用所以请帮忙!

public void onStart(Intent intent,int startid){

    Toast.makeText(getApplicationContext(),"Service Strated...",Toast.LENGTH_SHORT).show();
    device_id = intent.getExtras().getString("device_id");

    final int delay = 60000; //milliseconds
    h.postDelayed(new Runnable() {
        public void run() {
            try {
                get();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            h.postDelayed(this, delay);
        }
    }, delay);
}

public void get() throws JSONException {
    count++;
    gps=new GPSTracker(getApplicationContext());
    if(gps.canGetLocation()) {
        double latitude = gps.getLatitude();
        double longitude = gps.getLongitude();
        if (latitude != 0.0 & longitude != 0.0) {
            insert(latitude,longitude);
            Toast.makeText(getApplicationContext(), "Your Location : \n Lat :" + latitude + "\nLang :" + longitude, Toast.LENGTH_LONG).show();
            if(count==5){
                send();
                count=0;
            }
        }
    }
}

public void insert(double lat,double lon){
    System.out.print("hi_entered");
    boolean exist = checkIfExist(lat, lon);
    System.out.print(exist);
    if(!exist) {
        System.out.print("INSERT INTO location VALUES(null,'" + lat + "','" + lon + "',null);");
        db.execSQL("INSERT INTO location VALUES(null,'" + lat + "','" + lon + "',null);");
    }
}

0 个答案:

没有答案