Created
June 3, 2013 17:24
-
-
Save phpmaps/5699732 to your computer and use it in GitHub Desktop.
Android polling example which gets triggered every 10 seconds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void getLocationPeriodically() { | |
mHandler = new Handler() { | |
@Override | |
public void handleMessage(Message msg) { | |
Location l = (Location) msg.obj; | |
Toast.makeText(getApplicationContext(), "Latitude: " + String.valueOf(l.getLatitude()) + " Longitude: " + String.valueOf(l.getLongitude()), | |
Toast.LENGTH_LONG).show(); | |
} | |
}; | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
while (true) { | |
try { | |
Thread.sleep(10000); | |
mHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
Location l = BasicReceiver.fieldLocation; | |
Message msg = new Message(); | |
msg.obj = l; | |
mHandler.sendMessage(msg); | |
} | |
}); | |
} catch (Exception e) { | |
} | |
} | |
} | |
}).start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`mRunnable=new Runnable() {
to execute just call
mHandler.post(mRunnable)