我正在尝试将设置片段添加到我的Android应用程序中。因此,我添加了一个XML文件和这个活动:
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
}
它被从主活动的onOptionsItemSelected函数调用:
if (id == R.id.action_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
所以,现在当我尝试从菜单打开这个活动时,它会强制关闭并在控制台中出现以下错误:
Force-removing child win Window{4190a9a8 u0 PopupWindow:418fc208} from container Window{418dd448 u0 org.name.app/org.name.app.MainActivity}
Failed looking up window
java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@423b1fc0 does not exist
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7934)
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7925)
at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1047)
at android.os.BinderProxy.sendDeathNotice(Binder.java:493)
at dalvik.system.NativeStart.run(Native Method)