Android - BroadcastReceiver trying to return result during a non-ordered broadcast
I am trying to catch the BOOT_COMPLETED intent. In my receiver, I just print something to the Log. In Logcat I get this error, and the log statement that I put never prints out. I have set the permission in the manifest for
<uses-permission android:name="开发者_如何学JAVAandroid.permission.RECEIVE_BOOT_COMPLETED" />
And have also declared the required intent filter in my receiver. What am I doing wrong?
What am I doing wrong?
That's impossible to answer given the limited information you have supplied. Perhaps your action string is wrong in your <intent-filter>
.
Here is a sample project that does just what you describe (boot-time receiver writing a message to LogCat).
I had the problem too, found this answer and solved it by diffing with CommonsWare's sample code:
You will get this error, when you call setResultData(...) in the onReceive()-Method of the BroadcastReceiver and reacting to a non-ordered Broadcast. It looks like the boot broadcast is non-ordered. see also: Developer docs
@Override
public void onReceive(Context context, Intent intent)
{
try
{
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
// setResultData(null);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
精彩评论