implement LocationListener instead of using TimerTask
Updating UI from TimerTask
-
13-10-2022 - |
Question
I am implementing an application that get the location data in certain intervals of time and checks the location got is the destination. If current location is the destination I want to Toast or update a TextField. I used TimerTask for this. But it is not giving me the correct output. While I searched I saw that TimerTask cannot handle changes in the UI. Is there any way to solve my problem? I want to check in certain intervals and want to update UI
Solution 3
OTHER TIPS
Just use runOnUiThread()
:
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(yourContext, "Data: ", Toast.LENGTH_SHORT).show();
}
});
you can use a handler
to notify the ui thread.
http://developer.android.com/training/multiple-threads/communicate-ui.html http://developer.android.com/reference/android/os/Handler.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow