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); ...

Get Hello, Android, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.