gpt4 book ai didi

android - 如何在库 Activity 的 manifest.xml 中指定 .Preference Activity

转载 作者:行者123 更新时间:2023-11-30 04:48:04 25 4
gpt4 key购买 nike

我在 TicTacToe 示例应用程序之后对我的代码进行建模,所以我的设置是我有一个应用程序,它基本上是一个启动公共(public) Activity 的外壳,该 Activity 位于一个单独的 eclipse 项目中,标记为共享库(属性-> IsALibrary) .我已将库添加到调用 Activity 的属性中。我调用共享库代码如下:

    private void startGame()
{
Intent i = new Intent( this, calendar.class );
startActivityForResult( i, START_APPLICATION );
}

我的调用 Activity 的 AndroidManifest 如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.calendar" android:screenOrientation="portrait"
android:versionCode="1" android:versionName="1.0">
<application android:label="@string/app_name"
android:debuggable="true" android:icon="@drawable/icon">

<activity android:name=".MainActivity"
android:screenOrientation="portrait" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- This is defined in CalendarLib. Right now we need to manually copy
it here. Eventually it should get merged automatically. -->
<activity
android:name="com.library.calendar" >
</activity>

<!-- <activity android:name=".Preferences" android:label="@string/prefTitle"-->
<!-- android:screenOrientation="nosensor">-->
<!-- <intent-filer>-->
<!-- <action android:name="com.calendar.library.Preferences" />-->
<!-- <catagory android:name="android.intent.catagory.PREFERENCE" />-->
<!-- </intent-filer>-->
<!-- </activity>-->

</application>

<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


<supports-screens android:anyDensity="false"
android:resizeable="true" android:largeScreens="true"
android:normalScreens="true" android:smallScreens="false" />

</manifest>

共享库的AndroidManifest如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.calendar.library" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<!-- The activity tag here is currently not used. The main project must
currently redefine the activities to be used from the libraries. However
later the tools will pick up the activities from here and merge them automatically,
so it's best to define your activities here like for any regular Android
project. -->
<activity android:name="calendar" />

<activity android:name=".Preferences" android:label="@string/prefTitle"
android:screenOrientation="nosensor">
<intent-filer>
<action android:name=".Preferences" />
<catagory android:name="android.intent.catagory.PREFERENCE" />
</intent-filer>
</activity>

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

</manifest>

我在共享库代码的 Activity 类中定义我的菜单并按如下方式调用它:

case MENU_SETTINGS:
Intent intent = new Intent().setClass( this, Preferences.class );
this.startActivityForResult( intent, 0 );
return true;

当我点击设置时,我在 Instrumentation.java 的 execStartActivity() 方法中得到 START_INTENT_NOT_RESOLVED。查看 execStartActivity 试图启动的 Intent ,我看到了

mPackage="com.barrett.calendar" 
mClass="com.ifundraizer.calendar.library.Preferences"

其他一切都是空的,这并不奇怪。

我的问题是:

首选项 Activity 的定义属于调用 Activity 的 list 还是共享库的 list ,类的定义在 xml 中应该是什么样子?

谢谢你抽出时间,我希望我说清楚了,这很令人困惑。

最佳答案

仔细阅读共享库 list 中的评论:

<!-- The activity tag here is currently not used. The main project TicTacToeMain
must currently redefine the activities to be used from the libraries.
However later the tools will pick up the activities from here and merge them
automatically, so it's best to define your activities here like for any
regular Android project.
-->

基本上,您需要将共享库 list 中的所有 Activity 复制到使用这些 Activity 的应用程序。基本上将其添加到您的应用程序 AndroidManifest.xml:

<activity android:name=".Preferences" android:label="@string/prefTitle"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name=".Preferences" />
<category android:name="android.intent.category.PREFERENCE" />
</intent-filter>
</activity>

我看到你实际上复制了这部分,但是把它注释掉了。所以只需取消注释即可。

关于android - 如何在库 Activity 的 manifest.xml 中指定 .Preference Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4339785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com