开发者

Monkey starting intent in subactivity causes ANR

I have an android app with a button on the main activity that creates a second PreferenceActivity to display settings.

The manifest looks like this

<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>

The problem arises when I was using Monkey to test. It will start my app, then press the button to create my PreferenceActivity. Once the PreferenceActivity is created, monkey will send an intent to start another package. The PreferenceActivity will pause and the other package runs. Then monkey sends another intent to start my original app. I see my PreferenceActivity enter the onRes开发者_开发技巧ume() and then it freezes and ANR occurs.

I see in my 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)

I removed everything in my PreferencesActivity so all it has left is

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);
  }
}

I still get the ANR when resuming the PreferenceActivity. BUT, if I change it to extend Activity instead of PreferenceActivity and remove the preference things in onCreate(), I don't get the ANR anymore. I also don't get an ANR if I try to start intents manually with "adb shell am", so my problem only occurs when I run Monkey.

Any help would be most appreciated. Thank you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜