protected void onHandleWork()

in appindexing/app/src/main/java/com/google/firebase/example/appindexing/AppIndexingUpdateService.java [32:63]


    protected void onHandleWork(@NonNull Intent intent) {
        // TODO Insert your Indexable objects — for example, the recipe notes look as follows:

        ArrayList<Indexable> indexableNotes = new ArrayList<>();

        for (Recipe recipe : getAllRecipes()) {
            Note note = recipe.getNote();
            if (note != null) {
                Indexable noteToIndex = Indexables.noteDigitalDocumentBuilder()
                        .setName(recipe.getTitle() + " Note")
                        .setText(note.getText())
                        .setUrl(recipe.getNoteUrl())
                        .build();

                indexableNotes.add(noteToIndex);
            }
        }

        if (indexableNotes.size() > 0) {
            Indexable[] notesArr = new Indexable[indexableNotes.size()];
            notesArr = indexableNotes.toArray(notesArr);

            // batch insert indexable notes into index
            try {
                Tasks.await(FirebaseAppIndex.getInstance(this).update(notesArr));
            } catch (ExecutionException e) {
                // update failed
            } catch (InterruptedException e) {
                // await was interrupted
            }
        }
    }