【问题标题】:Android Activity.Not.Found IntentAndroid Activity.Not.Found Intent
【发布时间】:2013-01-29 23:26:29
【问题描述】:

我有一个 Activity 正在运行,当我单击一个按钮时,我希望弹出下一个 Activity。它应该很简单,但我不知道这里发生了什么。 我不明白为什么我会收到这个错误。我查看了其他人的错误并尝试修复它,但没有任何效果。当我匹配动作名称并在 java 中调用它时,我仍然会收到此错误。我不确定我做错了什么。

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jordan.dictation"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        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=".Recorder" 
        android:theme="@style/AppBaseTheme"
        android:label="@string/app_name" >
        <action android:name="com.jordan.dictation.RECORDER" />
        <category android:name="android.intent.category.DEFAULT" />
    </activity>
</application>

这是我的第一个活动的 Java 代码,假设在单击按钮时会调用另一个活动“Recorder.java”:

    public class MainActivity extends Activity {

Button bn_Add;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bn_Add = (Button) findViewById(R.id.button_nav_add_recording);
    bn_Add.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO start other activity
            try
            {
                // this is the code that I am surrounding in the try/catch block
                Intent openRecorder = new Intent("com.jordan.dictation.RECORDER");
                startActivity(openRecorder);
            }
            catch (Exception e)
            {
                // this is the line of code that sends a real error message to the log
                Log.e("ERROR", "ERROR IN CODE: " + e.toString());

                // this is the line that prints out the location in
                // the code where the error occurred.
                e.printStackTrace();
            }


        }
    });

【问题讨论】:

  • Recorder.java 放置在与 MainActivity.java 不同的包中吗?
  • 不,但很好猜。我只需要一个意图过滤器。

标签: android error-handling android-activity


【解决方案1】:

试试这个

<activity android:name=".Recorder" 
    android:theme="@style/AppBaseTheme"
    android:label="@string/app_name" >
  <intent-filter>
    <action android:name="com.jordan.dication.RECORDER" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

您没有在 mainfest 文件中使用意图过滤器

【讨论】:

  • 非常感谢。意图过滤器究竟做了什么?如果您发现一些可以轻松解释的内容,请分享!再次感谢!
  • 它基本上让系统知道组件的功能。例如,一个可以显示网页的 Activity 将声明它的意图过滤器如下: 过滤器>
  • 感谢您的解释。还有一个问题,因为它仍然与您已解决的问题有关...当我进行修复时(它有效,不要误会我)但为什么我会收到警告 {Exported activity doesn't require permission} at每个不是主要活动的活动?再次感谢!
  • 此警告意味着您的活动会暴露给不同进程的应用程序,这些应用程序可能会在没有任何必要权限的情况下实例化它们。详情见:developer.android.com/guide/topics/manifest/…developer.android.com/guide/topics/manifest/…
  • 我找到了答案,谢谢! android:exported="false"
【解决方案2】:

试试看:

Intent intent = new Intent(MainActivity.this, Recorder.class);
startActivity(intent);

而不是

Intent openRecorder = new Intent("com.jordan.dictation.RECORDER");
startActivity(openRecorder);

清理并构建您的代码以确保!

【讨论】:

  • 它更高效还是你认为它只是读起来更好?
  • 总是为我工作!此外,在我看来,通过 Action 启动 Intent (让系统为你找到它)而不是通过类名立即打开更复杂!查看文档:developer.android.com/reference/android/content/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
  • 1970-01-01
  • 2014-08-05
  • 2017-06-21
  • 1970-01-01
  • 2011-07-12
相关资源
最近更新 更多