猴子在子活动中的起始意图会导致ANR

问题描述

| 我有一个Android应用程序,其主活动上带有一个按钮,可创建第二个PreferenceActivity以显示设置。 清单看起来像这样
<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将暂停,其他程序包将运行。然后,猴子发送另一个意图启动我的原始应用程序。我看到我的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。但是,如果我将其更改为扩展Activity而不是PreferenceActivity并删除onCreate()中的首选项,我将不再获得ANR。如果我尝试使用\“ adb shell am \\”手动启动Intent,那么我也不会获得ANR,所以我的问题仅在运行Monkey时出现。 非常感激任何的帮助。 谢谢。     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...