Tuesday, September 10, 2013

[android help] Timer to schedule a task


Timer to schedule a task



I need to check continously a variable's value. This is a value that I receive from the bluetooth's input stream, this is the reasson why I need to this be continuosly checking it.


What I need to do too, is that when i call the function, it returns to me the value saved in the variable in that moment.


For that, I'm doing this:



private final Handler refresh_handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


Runnable refresh_input = new Runnable() {
@Override
public void run() {
bt_read_input = GlobalVar.bt_input; //Save received value in a local variable
refresh_handler.postDelayed(refresh_input, 500);
}
};
}

refresh_handler.post(refresh_input); //Call to the function


This seems to be refreshing the variable every 0,5sec. But I still need that when I call it, it returns to me the actual variable's value, this is, bt_read_input's value in that moment.


How could I implement a function to do this as a timer, but also to return the variable's value to get it when I want?



Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...