From 3c757036a3c0425ccabadb92e6e609bb2ea0a777 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Thu, 28 Apr 2016 15:11:26 -0700 Subject: [PATCH] Delay callback from printerRegistry after Constr. If the leader inside of the printer registry can immediately initalize the callback is called in the same thread as the contructor is executing. Hence in this case the mPrinterRegistry field is used before written. Change-Id: I45239d2792f6c31ec215ddb01131038882ff0136 --- .../src/com/android/printspooler/ui/PrintActivity.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index c4111864ba2d9..7fc6c9dccbc74 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -288,12 +288,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // the first batch of results which will be delivered // after reading historical data. This should be pretty // fast, so just wait before showing the UI. - mPrinterRegistry = new PrinterRegistry(PrintActivity.this, - new Runnable() { - @Override - public void run() { - onPrinterRegistryReady(documentAdapter); - } + mPrinterRegistry = new PrinterRegistry(PrintActivity.this, () -> { + (new Handler(getMainLooper())).post(() -> onPrinterRegistryReady(documentAdapter)); }, LOADER_ID_PRINT_REGISTRY, LOADER_ID_PRINT_REGISTRY_INT); }