I know this question has been asked before, but I've been over all of the answers I could find and still haven't been able to solve the problem.
The issue is that when by BroadcastReceiver starts the IntentService onHandleIntent() isn't called. Weirdly enough the constructor does run (as I can see by the Log output). This is my code:
NoLiSeA.class (This class contains the BroadcastReceiver that starts my service)
public void toProcess(StatusBarNotification sbn) {
LocalBroadcastManager.getInstance(this).registerReceiver(notificationForwarder, new IntentFilter("to_forward"));
Intent intent = new Intent("to_forward");
intent.putExtra("sbn", sbn);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
Log.i("NoLiSe.TAG", "toProcess");
}
private BroadcastReceiver notificationForwarder = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("NoLiSe.TAG", "BroadCastReceiver.onReceive");
Intent i = new Intent(context, CoreTwoA.class);
i.putExtras(intent);
startService(i);
}
}
};
CoreTwoA.class (This is the IntentService. onHandleIntent() is not called as I can see due to no log text in the console.)
public class CoreTwoA extends IntentService {
private TextToSpeech mtts;
public CoreTwoA() {
super("TheCoreWorker");
Log.d("source", "exception", new Exception());
Log.i("CoreTwoA.TAG", "Constructor");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.i("CoreTwoA.TAG", "onHandleIntent");
}
}
AndroidManifest.xml
<service
android:name=".CoreTwoA"
android:label="@string/service_name"
android:exported="false">
</service>
UPDATE
So based on discussions below, I was able to narrow down the problem to the following line of code in the BroadCastReceiver:
i.putExtra("sbn", sbn)
If I remove it, i.e. add no extras to the intent, then my the onHandleIntent() method in my IntentService does run.
If it is included, onHandleIntent() doesn't run and the following is written to logcat by the Log.d() in the Constructor of my IntentService
06-10 19:40:35.355 25094-25094/com.dezainapps.myapp D/source: exception
java.lang.Exception
at com.dezainapps.myapp.CoreTwoA.<init>(CoreTwoA.java:20)
at java.lang.Class.newInstance(Native Method)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap4(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-10 19:40:35.355 25094-25094/com.dezainapps.myapp I/CoreTwoA.TAG: Constructor
Any ideas why passing a StatusBarNotification object, that implements Parcelable, to a IntentService via an Intent doesn't work? Oddly enough broadcasting the same StatusBarNotfication sbn object from my toProcess() method via an intent (see code) does work.