开发者

Android ActivityNotFoundException

开发者 https://www.devze.com 2023-02-09 07:39 出处:网络
I\'m trying to create a very simple custom intent example. I\'ve searched for this error and none of the forums have answers that work for me. Here are my files:

I'm trying to create a very simple custom intent example. I've searched for this error and none of the forums have answers that work for me. Here are my files:

public class DemoImplicit extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void whenButtonIsClicked(View view) {
        Intent intent = new Intent("com.example.action.NEW_ACTION"); //<<<<<<<
        intent.addCategory("android.intent.category.DEFAULT");       //<<<<<<<
//      Intent intent = new Intent("android.intent.action.VIEW");
//      intent.addCategory("com.example.MY_CATEGORY");
        startActivity(intent);                                       //<<<<<<<
    }
}

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.demos" android:versionCode="1"
    android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SatisfyIntent" android:label="@string/app_name">

          <intent-filter>
            <!-- action android:name="android.intent.action.VIEW" / -->
            <!-- category android:name="com.example.MY_CATEGORY" / -->
            <action android:name="com.example.action.NEW_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="9" />

</manifest> 

These two separate files are in two different Eclipse projects, but I make sure to load the project containing the intent-filter onto the emulator before loading the file containing the startActivity call onto the emulator. In any case, I always get an ActivityNotFoundException. What am I doing wrong?

P.S. Here's the AndroidManifest.xml file for the project containing DemoImplicit.java:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.demos"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".DemoImplicit"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent开发者_开发知识库-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="9" />

</manifest> 


Fisrtly you shuld ensure that your AndroidManifest.xml file must have defined the DemoImplicit Activity in this.

As like this:<activity android:name=".DemoImplicit"/>

Also in your code you have aspecified the SatisfyIntent as a launcher Activity

<activity android:name=".SatisfyIntent" android:label="@string/app_name">

But here it seems like you have nothing like this in your Java Code.

So the Bottom line is that: Activity which you want to run must have defined in your AndroidManifest.xml file.

0

精彩评论

暂无评论...
验证码 换一张
取 消