Search code examples
javaandroidbroadcastreceiverandroid-manifestandroid-alertdialog

no activity found to handle intent from broadcast receiver


I am trying to call a dialogue themed activity from a broadcast receiver. My Manifest declaration looks like:

 <activity android:name=".Views.DialogueActivity"
        android:theme="@android:style/Theme.Dialog">
        <intent-filter>
            <action android:name="com.example.tictactoe.CUSTOM_DIALOGUE" />
        </intent-filter>
    </activity>

My broadcast receiver:

public class WinReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent i = new Intent();
    i.setAction("com.example.tictactoe.CUSTOM_DIALOGUE");
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
}}

My Activity is a dialogue themed activity and I get a error:

FATAL EXCEPTION: main
              Process: com.example.akshay.ticktactoe, PID: 18301
              java.lang.RuntimeException: Unable to start receiver com.example.akshay.ticktactoe.Views.Helpers.WinReceiver: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.tictactoe.CUSTOM_DIALOGUE flg=0x10000000 }
                  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586)
                  at android.app.ActivityThread.access$1700(ActivityThread.java:144)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5221)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

What seems to be the problem? Am I declaring the action of the activity correctly?


Solution

  • Use an explicit Intent: Intent i = new Intent(context, DialogueActivity.class); and eliminate the action string from the Intent and the <intent-filter> from the manifest.

    Only use an <intent-filter> if third-party apps need to be able to start the activity directly.