无法在 Android 库模块中启动 Activity [英] Cannot Launch Activity in Android Library Module

查看:32
本文介绍了无法在 Android 库模块中启动 Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android 应用项目中,我添加了一个模块,其中包含一个名为SampleDataMenuActivity"的活动.此活动没有什么特别之处 - 它是使用 Android Studio 中的新模块"->Android 库"对话框添加的,并包含由 Android Studio 生成的Hello World"代码.

To my Android app project, I added a module which contains an activity named "SampleDataMenuActivity". There is nothing special to this activity - it's added using the "New Module" -> "Android Library" dialog in Android Studio and includes the "Hello World" code generated by Android Studio.

应用的 AndroidManifest.xml 包括(来自模块):

The AndroidManifest.xml of the app includes (from the module):

<activity
    android:name="com.sample.sampledata.SampleDataMenuActivity" >
    <intent-filter>
        <action android:name="android.intent.action.SampleDataMenuActivity" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

在应用的 build.gradle 中:

In the build.gradle of the app:

dependencies {
    (...)
    compile project(':sampledata')
}

在项目的settings.gradle中:

In the settings.gradle of the project:

include ':sampledata', ':app'

在我的应用程序的主要活动中,我想使用以下方法导航到模块中的活动:

In the main activity of my app, I want to navigate to an activity in the module using:

startActivity(new Intent("com.sample.sampledata.SampleDataMenuActivity"));

项目构建得很好,但是当我点击应该带我进入模块中的活动的按钮时,它失败了,报告:

The project builds just fine, but when I tap the button that should take me to the activity in the module it fails, reporting:

android.content.ActivityNoFoundException: No Activity found to handle Intent ( act=com.sample.sampledata.SampleDataMenuActivity )

我错过了什么?

推荐答案

我发现了错误,也许我应该删除这个问题.但是当它被投票时,其他人可能对这个答案感兴趣:

I found the mistake, and perhaps I should remove the question. But as it was upvoted, somone else might be interested in this answer:

清单应说明:

<activity
    android:name="com.sample.sampledata.SampleDataMenuActivity" >
    <intent-filter>
        <action android:name="com.sample.sampledata.SampleDataMenuActivity" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

这篇关于无法在 Android 库模块中启动 Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆