【问题标题】:why my application is not able find activity to handle an intent为什么我的应用程序无法找到处理意图的活动
【发布时间】:2014-02-05 06:51:24
【问题描述】:

我正在使用选项菜单的开关盒。但我得到了一些错误。我已经检查了 logcat 也说

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.app1.ABOUT }

下面给出了我在 java 类中编写的一小段代码。

public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.aboutus:
        Intent i = new Intent("com.app1.ABOUT");
        startActivity(i);
        break;

    case R.id.preferences:
        Intent s = new Intent("com.app1.PREFS");
        startActivity(s);

        break;
    case R.id.exit:
        finish();
        break;

    }
    return false;
}

android manifest的代码如下。

 <activity
        android:name="com.app1.Aboutus"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
            <action android:name="android.intent.action.ABOUT" />

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

我是否从我的 java 类中以正确的方式裁判清单?

【问题讨论】:

  • com.app1.PREFScom.app1.ABOUT 名称作为活动添加到清单文件并使用(context , class) 更改意图构造函数

标签: android android-intent android-manifest


【解决方案1】:

试试这个你的清单..

    <activity
        android:name="com.app1.Aboutus"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

      <activity android:name="com.app1.ABOUT"/>         

      <activity android:name="com.app1.PREFS"/>        

在java中

case R.id.aboutus:
    Intent i = new Intent(Aboutus.this, ABOUT.class);
    startActivity(i);
    break;

case R.id.preferences:
    Intent s = new Intent(Aboutus.this, PREFS.class);
    startActivity(s);

【讨论】:

  • 可以有另一种方法来解决这个问题,但我想知道我错在哪里。我的代码有什么问题?
【解决方案2】:
    // I  can modify like this
     Intent i = new Intent(Activity1.ths, Activity2.class);
     startActivity(i);

【讨论】:

    【解决方案3】:

    您在意图中使用的包名称和清单中的名称不同。因此,将清单中的活动名称更改为:

    <activity android:name="com.app1.ABOUT"/>         
    <activity android:name="com.app1.PREFS"/> 
    

    因为这些是您在意图中使用的名称。

    Intent s = new Intent("com.app1.PREFS");
    

    因此,在清单中和在意图中使用时应该是相同的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-18
      • 2013-08-24
      相关资源
      最近更新 更多