From 9440fdbffb1af2876b2d2fde867b2c12250ef85b Mon Sep 17 00:00:00 2001 From: Jesse Young Date: Mon, 19 Sep 2011 19:51:08 -0700 Subject: [PATCH] android's ForegroundService example code is surprisingly buggy --- src/org/envaya/kalsms/ForegroundService.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/org/envaya/kalsms/ForegroundService.java b/src/org/envaya/kalsms/ForegroundService.java index 039e97e..a2f09d3 100755 --- a/src/org/envaya/kalsms/ForegroundService.java +++ b/src/org/envaya/kalsms/ForegroundService.java @@ -56,7 +56,7 @@ public class ForegroundService extends Service { void invokeMethod(Method method, Object[] args) { try { - mStartForeground.invoke(this, mStartForegroundArgs); + method.invoke(this, args); } catch (InvocationTargetException e) { // Should not happen. Log.w("ApiDemos", "Unable to invoke method", e); @@ -93,15 +93,7 @@ public class ForegroundService extends Service { // If we have the new stopForeground API, then use it. if (mStopForeground != null) { mStopForegroundArgs[0] = Boolean.TRUE; - try { - mStopForeground.invoke(this, mStopForegroundArgs); - } catch (InvocationTargetException e) { - // Should not happen. - Log.w("ApiDemos", "Unable to invoke stopForeground", e); - } catch (IllegalAccessException e) { - // Should not happen. - Log.w("ApiDemos", "Unable to invoke stopForeground", e); - } + invokeMethod(mStopForeground, mStopForegroundArgs); return; } @@ -121,10 +113,10 @@ public class ForegroundService extends Service { mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); + return; } catch (NoSuchMethodException e) { // Running on an older platform. mStartForeground = mStopForeground = null; - return; } try { mSetForeground = getClass().getMethod("setForeground",