为什么 Android 帐户 &尝试查找我的设置活动时同步重新启动?
我有一个可以声明为启动器类别的活动,并且它可以从主屏幕正常启动。但是,当我尝试将相同的活动连接到我的 SyncAdapter 的设置活动并从帐户和帐户中打开它时,同步页面-> MySyncAdapter -> (触摸帐户列表)它因系统致命错误而中止(重新启动手机)。
与此同时,我的 SyncAdapter 正在其他方面工作。
以下是影响点的日志:
01-13 12:31:00.976 5024 5038 I ActivityManager: Starting activity: Intent { act=android.provider.Settings.ACTION_SYNC_SETTINGS flg=0x10000000 cmp=com.myapp.android.syncadapter.ui/SyncAdapterSettingsActivity.class (has extras) }
01-13 12:31:00.985 5024 5038 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
01-13 12:31:00.985 5024 5038 E AndroidRuntime: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp.android.syncadapter.ui/SyncAdapterSettingsActivity.class}; have you declared this activity in your AndroidManifest.xml?
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.ContextImpl.startActivity(ContextImpl.java:622)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.preference.Preference.performClick(Preference.java:828)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:190)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.ListView.performItemClick(ListView.java:3382)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:587)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Looper.loop(Looper.java:123)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at com.android.server.ServerThread.run(SystemServer.java:517)
01-13 12:31:00.985 5024 5038 I Process : Sending signal. PID: 5024 SIG: 9
01-13 12:31:01.005 5019 5019 I Zygote : Exit zygote because system server (5024) has terminated
01-13 12:31:01.015 1211 1211 E installd: eof
这是清单文件中的一个片段:
<activity android:name="com.myapp.android.syncadapter.ui.SyncAdapterSettingsActivity"
android:label="@string/title_settings"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.provider.Settings.ACTION_SYNC_SETTINGS"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我忘记了引用的 XML 资源文件 (account_preferences.xml)。它提供了另一个级别的间接引用——对活动名称的引用。我可以操纵它来使日志条目相应地更改。所以,我认为这是解决方案的一个暗示。目标包和目标类连接在一起以定义要启动的活动的名称。我在日志中注意到路径名中有一个斜杠(/),我认为这就是它无法找到该活动的原因。例如,如果我从包中取出 (.ui) 并将其放入目标活动中,则斜线会移动到 .ui 中的 .ui 之前小路。
account_preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/format_auth_preferences" />
<PreferenceScreen
android:key="key_syncadapter_auth"
android:title="@string/key_syncadapter_auth_action"
android:summary="@string/key_syncadapter_auth_summary">
<intent
android:action="android.provider.Settings.ACTION_SYNC_SETTINGS"
android:targetPackage="com.myapp.android.syncadapter.ui"
android:targetClass=".SyncAdapterSettingsActivity" />
</PreferenceScreen>
</PreferenceScreen>
日志片段:
01-14 14:34:34.270 E/AndroidRuntime( 6374): *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
01-14 14:34:34.270 E/AndroidRuntime( 6374): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp.android.syncadapter.ui/.SyncAdapterSettingsActivity}; have you declared this activity in your AndroidManifest.xml?
I have an activity that I can declare as Launcher category and it launches just fine from the home screen. However, when I try to hook-up the same activity into my SyncAdapter's settings activity and open it from the Accounts & Sync page -> MySyncAdapter -> (touch account listing) it aborts with a system fatal error (reboots phone).
Meanwhile, my SyncAdapter is working other respects.
Here is the log at point of impact:
01-13 12:31:00.976 5024 5038 I ActivityManager: Starting activity: Intent { act=android.provider.Settings.ACTION_SYNC_SETTINGS flg=0x10000000 cmp=com.myapp.android.syncadapter.ui/SyncAdapterSettingsActivity.class (has extras) }
01-13 12:31:00.985 5024 5038 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
01-13 12:31:00.985 5024 5038 E AndroidRuntime: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp.android.syncadapter.ui/SyncAdapterSettingsActivity.class}; have you declared this activity in your AndroidManifest.xml?
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.ContextImpl.startActivity(ContextImpl.java:622)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.preference.Preference.performClick(Preference.java:828)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:190)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.ListView.performItemClick(ListView.java:3382)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:587)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Looper.loop(Looper.java:123)
01-13 12:31:00.985 5024 5038 E AndroidRuntime: at com.android.server.ServerThread.run(SystemServer.java:517)
01-13 12:31:00.985 5024 5038 I Process : Sending signal. PID: 5024 SIG: 9
01-13 12:31:01.005 5019 5019 I Zygote : Exit zygote because system server (5024) has terminated
01-13 12:31:01.015 1211 1211 E installd: eof
Here is a snippet from my manifest file:
<activity android:name="com.myapp.android.syncadapter.ui.SyncAdapterSettingsActivity"
android:label="@string/title_settings"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.provider.Settings.ACTION_SYNC_SETTINGS"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I forgot about the XML resource file (account_preferences.xml) that is referenced. It provides another level of indirection-reference to the activity's name. I can manipulate it to get the log entry to change accordingly. So, I think that is a hint to the solution. The target package and target class get concatenated together to define the name of the activity to start. What I noticed in the log is that there is a slash (/) in the path name and I think that is why it is unable to find the activity. For example, if I take the (.ui) out of the package and put it in the target-activity, then the slash moves to be before the .ui in the path.
account_preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/format_auth_preferences" />
<PreferenceScreen
android:key="key_syncadapter_auth"
android:title="@string/key_syncadapter_auth_action"
android:summary="@string/key_syncadapter_auth_summary">
<intent
android:action="android.provider.Settings.ACTION_SYNC_SETTINGS"
android:targetPackage="com.myapp.android.syncadapter.ui"
android:targetClass=".SyncAdapterSettingsActivity" />
</PreferenceScreen>
</PreferenceScreen>
log snippet:
01-14 14:34:34.270 E/AndroidRuntime( 6374): *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread
01-14 14:34:34.270 E/AndroidRuntime( 6374): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp.android.syncadapter.ui/.SyncAdapterSettingsActivity}; have you declared this activity in your AndroidManifest.xml?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了它!基本上,包是根包,目标类是完全限定名称。
我还必须仔细检查我的 AndroidManifest,以确保这些值拼写正确,以便它们可以匹配,并且我有一个对活动响应有意义的意图过滤器。
现在我必须实现设置配置活动并正确格式化 Intent 中的结果。我感觉到我还有另一个问题:)
I got it! Basically, the package is the root package and the target class is the fully qualified name.
I also had to carefully check my AndroidManifest to be certain that the values were correctly spelled so they could match and that I had an intent-filter that was meaningful for the activity to respond to.
Now I have to implement the settings config activity and format the result in an Intent correctly. I sense another question coming from me :)