Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

android - ActivityNotFoundException?

I am getting an ActivityNotFoundException in the following code:

Main.java

Intent intent = new Intent();
     intent.setAction("com.test.app.TEST");
     startActivity(intent); // ActivityNotFoundException

Manifest.xml

<activity android:name=".MainActivity" android:theme="@android:style/Theme.Dialog">
        <intent-filter>
            <action android:name="com.test.app.TEST" />
        </intent-filter>
</activity>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've had this issue too, as perfectly concisely described by jpahn.

the period at the front did not give any help to me.

even with exactly this (a copy of the original question including edits), I would still get ActivityNotFoundException.

Main.java

Intent intent = new Intent();
 intent.setAction("com.test.app.TEST");
 startActivity(intent); // ActivityNotFoundException

Manifest.xml

<activity android:name=".MainActivity" android:theme="@android:style/Theme.Dialog">
    <intent-filter>
        <action android:name="com.test.app.TEST" />
    </intent-filter>
</activity>

This was resolved, after much trial-and-error, by simply adding this to the intent-filter in the manifest:

<category android:name="android.intent.category.DEFAULT" />

So the final manifest file contained:

<activity android:name=".MainActivity" android:theme="@android:style/Theme.Dialog">
    <intent-filter>
        <action android:name="com.test.app.TEST" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...