From: Michael Gernoth Date: Mon, 29 Oct 2012 14:06:46 +0000 (+0100) Subject: start service while booting to prevent module-loading getting killed X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/ms2-fixes/commitdiff_plain/1a5cc22f549744032d98e89fb598440558f01148?ds=sidebyside;hp=f297054c1bfe38a7b55ed9becce37144e7b070ca start service while booting to prevent module-loading getting killed --- 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"); + } +}