I have an android app that has both an activity and a service. The service reads bluetooth sensor data from a Samsung Galaxy Gear 2. The galaxy gear is shooting out data as fast as it gets it buts theres incredible lag on the Android side of receiving it. The service is three lines of code so it really can't get more efficient than that. I think it's probably the activity code which I have written below:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
//set global variables
x = (TextView)findViewById(R.id.xaccel);
y = (TextView)findViewById(R.id.yaccel);
z = (TextView)findViewById(R.id.zaccel);
doBindService(); //Conects to the Service
Thread myThread = new Thread(myRunnable);
myThread.start();
}
Runnable myRunnable = new Runnable() {
@Override
public void run() {
while (mIsBound) {
//check that the global variables have been set
if (x!=null && y!= null && z != null) {
x.post(new Runnable() {
@Override
public void run() {
if (HelloAccessoryProviderService.inputMessage != "") {
//read the service's global variable "inputMessage" and print it out
String mainData = HelloAccessoryProviderService.inputMessage;
x.setText("X: " + mainData.substring(0, 6));
y.setText("Y: " + mainData.substring(7, 13));
z.setText("Z: " + mainData.substring(14, 20));
}
};
});
}
}
}
};
I read that runnables were the best way to read continuous data but if there are other ways, it would be great. Thanks in advance!