O'Reilly logo

Hello, Android, 4th Edition by Ed Burnette

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Threading the Needle

The update request is defined inside the initThreading method:

suggest/src/main/java/org/example/suggest/MainActivity.java
Line 1 
private​ ​void​ initThreading() {
guiThread = ​new​ ​Handler​();
suggThread = ​Executors​.newSingleThreadExecutor();
// This task gets suggestions and updates the screen
updateTask = ​new​ ​Runnable​() {
public​ ​void​ run() {
// Get text to suggest
String​ original = origText.getText().toString().trim();
10 
// Cancel previous suggestion if there was one
if​ (suggPending != null)
suggPending.cancel(true);
15 
// Check to make sure there is text to work on
if​ (original.length() != 0) {
// Let user know we're doing something
setText(R.string.working); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required