当用户按下操作栏中的up button
(并且该字段实际为空)时,我试图在片段中进行非空字段检查,但是我收到了下一个错误:
03-24 10:56:57.860 23770-23770/com.crimes.george.crime E/WindowManager: android.view.WindowLeaked: Activity com.bubbles.george.mybubbletea.PagerActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b2fc7268 V.E..... R.....I. 0,0-480,204} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:348)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:286)
at com.bubbles.george.crimes.Fragment.onOptionsItemSelected(Fragment.java:142)
at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2099)
at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:2238)
at android.support.v4.app.FragmentController.dispatchOptionsItemSelected(FragmentController.java:329)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:410)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:167)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.widget.ToolbarWidgetWrapper$1.onClick(ToolbarWidgetWrapper.java:192)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
我的代码是:
case android.R.id.home:
Log.d(TAG, "up button in action bar has been pressed!");
String titleField = mTitleField.getText().toString();
if (TextUtils.isEmpty(titleField)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.empty_title_message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create()
.show();
} else {
NavUtils.navigateUpFromSameTask(getActivity());
return true;
}
我期待的是当字段中包含某些内容时导航到上一个活动,否则会出现一个对话框窗口并停止导航。但不是那样,我得到微秒的对话框,然后导航继续到我当前活动的上一级。
我做错了什么?
提前致谢。