設定を表示するための 2 番目の PreferenceActivity を作成するメイン アクティビティのボタンを備えた Android アプリがあります。
マニフェストは次のようになります
<application android:name=".MyApp"
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".MyApp"
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=".Settings"></activity>
</application>
Monkey を使用してテストしたときに問題が発生しました。アプリが起動し、ボタンを押して PreferenceActivity を作成します。PreferenceActivity が作成されると、monkey は別のパッケージを開始するインテントを送信します。PreferenceActivity が一時停止し、他のパッケージが実行されます。次に、monkey が別のインテントを送信して、元のアプリを起動します。私の PreferenceActivity が onResume() に入ると、フリーズして ANR が発生します。
私のlogcatに表示されます:
INFO/ActivityManager(211): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.MyApp/.MyApp } from pid 4532
# Main activity is created and runs.
# Monkey presses settings button, which sends intent to start PreferenceActivity.
INFO/ActivityManager(211): Starting: Intent { cmp=com.example.MyApp/.Settings } from pid 4519
# PreferenceActivity is created and runs.
# Monkey sends intent to start other package. PreferenceActivity pauses.
INFO/ActivityManager(211): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.OtherApp/.OtherApp } from pid 4532
# Other app runs.
# Monkey sends intent to start MyApp again.
INFO/ActivityManager(211): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.MyApp/.MyApp } from pid 4532
# PreferenceActivity's onResume() method runs.
# Screen is blank.
ERROR/ActivityManager(211): ANR in com.example.MyApp (com.example.MyApp/.Settings)
PreferencesActivity のすべてを削除したので、残っているのは
public class Settings extends PreferenceActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
addPreferencesFromResource(R.xml.preferences);
}
}
PreferenceActivity を再開すると、まだ ANR が発生します。しかし、PreferenceActivity の代わりに Activity を拡張するように変更し、onCreate() の設定を削除すると、ANR が得られなくなります。また、「adb shell am」を使用してインテントを手動で開始しようとしても ANR が得られないため、Monkey を実行したときにのみ問題が発生します。
どんな助けでも大歓迎です。ありがとうございました。