From 1f32f067295d0aff56c373e9bc9069e2e712c21e Mon Sep 17 00:00:00 2001 From: daneren2005 Date: Wed, 21 Aug 2013 16:30:11 -0700 Subject: Background thread key event handling --- .../dsub/service/DownloadServiceLifecycleSupport.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 93eefeeb..fa21f9f0 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -164,9 +164,22 @@ public class DownloadServiceLifecycleSupport { public void onStart(Intent intent) { if (intent != null && intent.getExtras() != null) { - KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT); + final KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT); if (event != null) { - handleKeyEvent(event); + new Thread(new Runnable(){ + @Override + public void run() { + try { + // Make sure everything is ready to go before handling event + if(!setup.get()) { + lock.lock(); + } + handleKeyEvent(event); + } finally { + lock.unlock(); + } + } + }); } } } -- cgit v1.2.3