From 1a5cc22f549744032d98e89fb598440558f01148 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Mon, 29 Oct 2012 15:06:46 +0100 Subject: [PATCH 1/1] start service while booting to prevent module-loading getting killed --- MS2Debounce/AndroidManifest.xml | 8 ++- .../ms2debounce/DebounceBootReceiver.java | 4 +- .../ms2debounce/DebounceBootService.java | 56 +++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java diff --git a/MS2Debounce/AndroidManifest.xml b/MS2Debounce/AndroidManifest.xml index f54f163..fc249dc 100644 --- a/MS2Debounce/AndroidManifest.xml +++ b/MS2Debounce/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="8" + android:versionName="1.8"> + + diff --git a/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootReceiver.java b/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootReceiver.java index 14e76a9..a493070 100644 --- a/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootReceiver.java +++ b/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootReceiver.java @@ -11,9 +11,7 @@ public class DebounceBootReceiver extends BroadcastReceiver{ DebounceModuleHelper module = new DebounceModuleHelper(context); if (module.get_on_boot() && module.is_safe_to_load()) { - try { - module.loadModule(); - } catch (Exception e) {} + context.startService(new Intent(context, DebounceBootService.class)); } } } diff --git a/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java b/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java new file mode 100644 index 0000000..78e4274 --- /dev/null +++ b/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java @@ -0,0 +1,56 @@ +package de.rmdir.ms2debounce; + +import android.app.Service; +import android.content.Intent; +import android.content.Context; +import android.os.IBinder; +import android.os.AsyncTask; +import android.util.Log; + +public class DebounceBootService extends Service +{ + private static final String TAG = "DebounceBootService"; + + public IBinder onBind(Intent intent) + { + return null; + } + + @Override + public void onCreate() + { + Log.i(TAG, "Starting AsyncTask"); + new AsyncTask() { + @Override + protected Void doInBackground(DebounceBootService... svc) { + Context context = getApplicationContext(); + DebounceModuleHelper module = new DebounceModuleHelper(context); + + Log.i(TAG, "Loading Module"); + + try { + module.loadModule(); + } catch (Exception e) { + Log.e(TAG, "Got Exception: " + e.getMessage() + " (" + e.getCause() + ")"); + } + + svc[0].stopSelf(); + + return null; + } + }.execute(this); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) + { + Log.i(TAG, "Creating STICKY service"); + return START_STICKY; + } + + @Override + public void onDestroy() + { + Log.i(TAG, "Destroying service"); + } +} -- 2.39.5