Why does Android Account & Sync reboot when trying to find my settings activity?
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.and开发者_如何学运维roid.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?
I got it! Basically, the package is the root package and the target class is the fully qualified name.
<intent
android:action="android.provider.Settings.ACTION_SYNC_SETTINGS"
android:targetPackage="com.myapp.android.syncadapter"
android:targetClass="com.myapp.android.syncadapter.ui.SyncAdapterSettingsActivity" />
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 :)
精彩评论