start service while booting to prevent module-loading getting killed
authorMichael Gernoth <michael@gernoth.net>
Mon, 29 Oct 2012 14:06:46 +0000 (15:06 +0100)
committerMichael Gernoth <michael@gernoth.net>
Mon, 29 Oct 2012 14:06:46 +0000 (15:06 +0100)
MS2Debounce/AndroidManifest.xml
MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootReceiver.java
MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java [new file with mode: 0644]

index f54f163..fc249dc 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="de.rmdir.ms2debounce"
-      android:versionCode="7"
-      android:versionName="1.7">
+      android:versionCode="8"
+      android:versionName="1.8">
     <uses-sdk android:minSdkVersion="8" />
     <uses-configuration android:reqKeyboardType="qwerty" />
     <supports-screens android:smallScreens="false"
@@ -23,5 +23,9 @@
                        <category android:name="android.intent.category.HOME" />
                </intent-filter>
        </receiver>
+       <service
+               android:name=".DebounceBootService"
+               android.label="DebounceBootService">
+       </service>
     </application>
 </manifest> 
index 14e76a9..a493070 100644 (file)
@@ -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 (file)
index 0000000..78e4274
--- /dev/null
@@ -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<DebounceBootService, Void, Void>() {
+                       @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");
+       }
+}
Impressum, Datenschutz