我记得cursorwindow中每条记录会分配一个空间,大小是2M,不知道是不是这个原因,

解决方案 »

  1.   

    Cursor 操作时,记得try catch finally
    把下面这段放在 catch 和 finally 里。if(cursor!=null){
    cursor.close();
    cursor = null;
    }
      

  2.   

    cursor是自己声明Cursor xxx的那个对象吗?db需要colse吗?
      

  3.   

     Runnable thread = new Runnable(){ public void run() {
    // TODO Auto-generated method stub

    dbAdapter = new DatabaseAdapter(MonitoringService.this);
    dbAdapter.open();

    //  try {
    // Thread.sleep(5000);
    // } catch (InterruptedException e) {}

    // 截至启动机器
    // 获取移动网络接收、发送数据总量,单位为byte,以下同上
    mobileRx = TrafficStats.getMobileRxBytes();
    mobileTx = TrafficStats.getMobileTxBytes(); // 获取全部网络接收、发送数据总量
    totalRx = TrafficStats.getTotalRxBytes();
    totalTx = TrafficStats.getTotalTxBytes();

    // 计算WiFi网络接收、发送数据总量
    wifiRx = totalRx - mobileRx;
    wifiTx = totalTx - mobileTx;

    if (mobileRx == -1 && mobileTx == -1) {
    in.putExtra("mobileRx", "No");
    in.putExtra("mobileTx", "No");
    }
     else {
    mrx = (mobileRx - old_mobileRx); // 得到瞬时GPRS流量
    old_mobileRx = mobileRx;
    mtx = (mobileTx - old_mobileTx) ; // 得到瞬时GPRS流量
    old_mobileTx = mobileTx; mrx = (long) ((float) (Math.round(mrx * 100.0)) / 100);
    mtx = (long) ((float) (Math.round(mtx * 100.0)) / 100); in.putExtra("mobileRx", mrx / 1024 + "KB");
    in.putExtra("mobileTx", mtx/ 1024 + "KB");
    }
    if (wifiRx == -1 && wifiTx == -1) {
    in.putExtra("wifiRx", "No");
    in.putExtra("wifiTx", "No");
    } else {
    wrx = (wifiRx - old_wifiRx); // 得到瞬时wifi流量
    old_wifiRx = wifiRx;
    wtx = (wifiTx - old_wifiTx); // 得到瞬时wifi流量
    old_wifiTx = wifiTx;
    wrx = (long) ((float) (Math.round(wrx * 100.0)) / 100);// 保留两位小数
    wtx = (long) ((float) (Math.round(wtx * 100.0)) / 100);
    in.putExtra("wifiRx", wrx / 1024 + "KB");
    in.putExtra("wifiTx", wtx + "KB");
    }
    Date date = new Date() ;
    mobileRx_all += mrx; // 求同一天的数据之和
    mobileTx_all += mtx; // 求同一天的数据之和
    wifiTx_all += wtx; // 求同一天的数据之和
    wifiRx_all += wrx; // 求同一天的数据之和
    if(count==12){
    Cursor checkMobile = null;
    try{
    //如果存在该天GPRS流量的记录则跟新本条记录
    if(mobileTx_all!=0||mobileRx_all!=0){
    checkMobile = dbAdapter.check(1, date);//1 为 GPRS流量类型
      if(checkMobile.moveToNext()){
    long up = dbAdapter.getProFlowUp(1, date);
    long dw = dbAdapter.getProFlowDw(1, date);
    mobileTx_all += up ;
    mobileRx_all += dw ;
    dbAdapter.updateData(mobileTx_all, mobileRx_all, 1, date);
    System.out.println("geng xin le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);
    mobileTx_all=0;
    mobileRx_all=0;

    }
      if(!checkMobile.moveToNext()){

    dbAdapter.insertData(mobileTx_all, mobileRx_all, 1, date);
    System.out.println("cun chu le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);

    }
      
    }
    //如果数据库中没有今天的GPRS流量则插入一条信息
    }catch(Exception e){
    e.printStackTrace();
    }finally{ checkMobile.close();  
    }
      

  4.   

     Runnable thread = new Runnable(){ public void run() {
    // TODO Auto-generated method stub

    dbAdapter = new DatabaseAdapter(MonitoringService.this);
    dbAdapter.open();

    //  try {
    // Thread.sleep(5000);
    // } catch (InterruptedException e) {}

    // 截至启动机器
    // 获取移动网络接收、发送数据总量,单位为byte,以下同上
    mobileRx = TrafficStats.getMobileRxBytes();
    mobileTx = TrafficStats.getMobileTxBytes(); // 获取全部网络接收、发送数据总量
    totalRx = TrafficStats.getTotalRxBytes();
    totalTx = TrafficStats.getTotalTxBytes();

    // 计算WiFi网络接收、发送数据总量
    wifiRx = totalRx - mobileRx;
    wifiTx = totalTx - mobileTx;

    if (mobileRx == -1 && mobileTx == -1) {
    in.putExtra("mobileRx", "No");
    in.putExtra("mobileTx", "No");
    }
     else {
    mrx = (mobileRx - old_mobileRx); // 得到瞬时GPRS流量
    old_mobileRx = mobileRx;
    mtx = (mobileTx - old_mobileTx) ; // 得到瞬时GPRS流量
    old_mobileTx = mobileTx; mrx = (long) ((float) (Math.round(mrx * 100.0)) / 100);
    mtx = (long) ((float) (Math.round(mtx * 100.0)) / 100); in.putExtra("mobileRx", mrx / 1024 + "KB");
    in.putExtra("mobileTx", mtx/ 1024 + "KB");
    }
    if (wifiRx == -1 && wifiTx == -1) {
    in.putExtra("wifiRx", "No");
    in.putExtra("wifiTx", "No");
    } else {
    wrx = (wifiRx - old_wifiRx); // 得到瞬时wifi流量
    old_wifiRx = wifiRx;
    wtx = (wifiTx - old_wifiTx); // 得到瞬时wifi流量
    old_wifiTx = wifiTx;
    wrx = (long) ((float) (Math.round(wrx * 100.0)) / 100);// 保留两位小数
    wtx = (long) ((float) (Math.round(wtx * 100.0)) / 100);
    in.putExtra("wifiRx", wrx / 1024 + "KB");
    in.putExtra("wifiTx", wtx + "KB");
    }
    Date date = new Date() ;
    mobileRx_all += mrx; // 求同一天的数据之和
    mobileTx_all += mtx; // 求同一天的数据之和
    wifiTx_all += wtx; // 求同一天的数据之和
    wifiRx_all += wrx; // 求同一天的数据之和
    if(count==12){
    Cursor checkMobile = null;
    try{
    //如果存在该天GPRS流量的记录则跟新本条记录
    if(mobileTx_all!=0||mobileRx_all!=0){
    checkMobile = dbAdapter.check(1, date);//1 为 GPRS流量类型
      if(checkMobile.moveToNext()){
    long up = dbAdapter.getProFlowUp(1, date);
    long dw = dbAdapter.getProFlowDw(1, date);
    mobileTx_all += up ;
    mobileRx_all += dw ;
    dbAdapter.updateData(mobileTx_all, mobileRx_all, 1, date);
    System.out.println("geng xin le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);
    mobileTx_all=0;
    mobileRx_all=0;

    }
      if(!checkMobile.moveToNext()){

    dbAdapter.insertData(mobileTx_all, mobileRx_all, 1, date);
    System.out.println("cun chu le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);

    }
      
    }
    //如果数据库中没有今天的GPRS流量则插入一条信息
    }catch(Exception e){
    e.printStackTrace();
    }finally{ checkMobile.close();  
    }