Using Android Sensor Processor

I'm trying to read a few sensors with the Samsung Galaxy Tab GT-P1000, and they seem to clog the processor pretty much with respect to the applications I used.

As a test, I created a short program that implements a SensorEventListener for an accelerometer sensor, but does nothing with the sensor readings:

public class SensorTestActivity extends Activity implements SensorEventListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SensorManager oSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); oSensorManager.registerListener(this, oSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { // TODO Auto-generated method stub } @Override public void onSensorChanged(SensorEvent event) { // TODO Auto-generated method stub } } 

This leads to 10% permanent CPU usage during debugging (i.e. my device is connected to my PC) and 5% usage, but I don’t. If I use SENSOR_DELAY_FASTEST, the use of skyrockets will be constant 30% while I am debugging, and 20% until I will.

This creates a serious problem when I want to use several sensors, because all of them have a high level of CPU usage and without data processing. I used Compass apps from the Android Market, and none of them are using more than 5% of the processor at a given time, so I feel like I am missing something obviously obvious, but I can not find anyone else with the same problem .

I did not edit the manifest file or layout for this application - this is the default template made by Eclipse, and I added the Sensor.

UPDATE: my CPU usage read method is corrupted because I used the task manager to measure it. My application does not stop sensors using onPause when the task manager opens, while most other applications will do this.

+6
source share
1 answer

This leads to 10% permanent CPU usage during debugging (i.e. my device is connected to my PC) and 5% usage, but I don’t. If I use SENSOR_DELAY_FASTEST, the use of skyrockets will be constant 30% while I am debugging, and 20% until I will.

Then use SENSOR_DELAY_UI or SENSOR_DELAY_NORMAL , which update the sensor data less frequently and should consume correspondingly less processor time.

I used Compass applications from the Android Market, and none of them used more than 5% of the processor at the moment

They probably aren't using SENSOR_DELAY_GAME or SENSOR_DELAY_FASTEST .

In addition, different devices (possibly with different sensor chipsets) can lead to different CPU usage. For example, some devices chat annoyingly in LogCat devices, logs based on sensor readings will be proportionally slower.

In addition, I do not know how you measure processor load, but I do not know any officially supported means for this. Instead, I will focus on things like the frame rate in your game or whatever you write.

+4
source

Source: https://habr.com/ru/post/902116/


All Articles