1

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 
Coding Mash
  • 3,338
  • 5
  • 24
  • 45
Android
  • 25
  • 5
  • I need urgent solution for this. Please reply as soon as you can . Thanks – Android Oct 28 '12 at 15:23
  • SO is not the place for urgent solutions. – mah Oct 28 '12 at 15:32
  • sorry i din't mean to be rude.. i am very new to this community and to android.. Sorry. – Android Oct 28 '12 at 16:07
  • Fortunately , i have found an answer in this link http://stackoverflow.com/questions/9982433/android-accelerometer-not-working-when-screen-is-turned-off which says that its not the HTTP post not working but when the screen is off no accelerometer values are generated . Thank you – Android Oct 28 '12 at 19:57

1 Answers1

0

Fortunately , i have found an answer in this link Android accelerometer not working when screen is turned off which says that its not the HTTP post not working but when the screen is off no accelerometer values are generated . Thank you

Community
  • 1
  • 1
Android
  • 25
  • 5