I have a code which has an activity with a button which when clicked starts the accelerometer service .
Accelerometer service Uses PARTIAL_WAKE_LOCK
in the onStart()
as shown :
@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()
and in the onSensorChange(Sensor event) i have the code which logs the data to remote server using HTTP POSt as shown :
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
My problem is :
When the phone screen goes dark ,HTTP stops logging to the server . But when the screen is
bright even if the keypad is locked it logs data .
Please help me as i want to make this service run in background and log data to server even when
the screen is locked .
So , its working fine till the screen goes dark after which its not logging any data .
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