mirror of
https://github.com/cwinfo/envayasms.git
synced 2024-12-04 20:45:32 +00:00
android's ForegroundService example code is surprisingly buggy
This commit is contained in:
parent
9a574b3ab4
commit
9440fdbffb
@ -56,7 +56,7 @@ public class ForegroundService extends Service {
|
|||||||
|
|
||||||
void invokeMethod(Method method, Object[] args) {
|
void invokeMethod(Method method, Object[] args) {
|
||||||
try {
|
try {
|
||||||
mStartForeground.invoke(this, mStartForegroundArgs);
|
method.invoke(this, args);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
// Should not happen.
|
// Should not happen.
|
||||||
Log.w("ApiDemos", "Unable to invoke method", e);
|
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 we have the new stopForeground API, then use it.
|
||||||
if (mStopForeground != null) {
|
if (mStopForeground != null) {
|
||||||
mStopForegroundArgs[0] = Boolean.TRUE;
|
mStopForegroundArgs[0] = Boolean.TRUE;
|
||||||
try {
|
invokeMethod(mStopForeground, mStopForegroundArgs);
|
||||||
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);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +113,10 @@ public class ForegroundService extends Service {
|
|||||||
mStartForegroundSignature);
|
mStartForegroundSignature);
|
||||||
mStopForeground = getClass().getMethod("stopForeground",
|
mStopForeground = getClass().getMethod("stopForeground",
|
||||||
mStopForegroundSignature);
|
mStopForegroundSignature);
|
||||||
|
return;
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
// Running on an older platform.
|
// Running on an older platform.
|
||||||
mStartForeground = mStopForeground = null;
|
mStartForeground = mStopForeground = null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mSetForeground = getClass().getMethod("setForeground",
|
mSetForeground = getClass().getMethod("setForeground",
|
||||||
|
Loading…
Reference in New Issue
Block a user