我有一个代码,它有一个带有按钮的活动,单击该按钮会启动加速度计服务。
    Accelerometer service 用途如图PARTIAL_WAKE_LOCK:onStart()
@Override
public void onStart(Intent intent, int startId) {
 // TODO Auto-generated method stub
 super.onStart(intent, startId);
//Power Manager
PowerManager pm = (PowerManager)getApplicationContext().getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MY WK");
 wl.acquire();
 //Power Manager
 try{
mInitialized = false;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);  
mSensorManager.registerListener(this, mAccelerometer,SensorManager.SENSOR_DELAY_NORMAL);
} 
catch(Exception e)
 { 
  Log.e("acc","catch1");
  }
}// end of onStart()
  并且在 onSensorChange(Sensor event) 我有使用 HTTP POST 将数据记录到远程服务器的代码,如图所示:
synchronized public void onSensorChanged(SensorEvent event) {
          if( event.sensor.getType() == Sensor.TYPE_ACCELEROMETER )
           {
             //-----------------------------sending it to server---------
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("xaxis", xaxis));
                nameValuePairs.add(new BasicNameValuePair("yaxis", yaxis));
                nameValuePairs.add(new BasicNameValuePair("zaxis", zaxis));
           //------------------
    Thread networkThread = new Thread() {
    @Override
       public void run() {
    HttpClient httpclient1 = new DefaultHttpClient();
    HttpPost httppost1 = new HttpPost("http://www.xxxxx.com/filename.php");
       httppost1.setEntity(new UrlEncodedFormEntity(nameValuePairs));
       HttpResponse response1 = httpclient1.execute(httppost1);
    }
    };
    networkThread.start();
    //----------------------------------
  }//and of if
 }//end of onSensorChanged
我的问题是:
当手机屏幕变暗时,HTTP 停止登录服务器。但是当屏幕
亮时,即使键盘被锁定,它也会记录数据。
请帮助我,因为我想让该服务在后台运行并将数据记录到服务器,即使
屏幕被锁定。
因此,它工作正常,直到屏幕变暗之后它不记录任何数据。
Does HTTP not work with Partial_WAKE_Lock.
I searched for the answers but could not find any. Hoping to get some help ! 
Thank You