onStop中的编码崩溃了应用

时间:2017-08-25 08:29:15

标签: android android-layout

 public void onStop() {
        information=Option.getText().toString();
        if (!information.equals("")) {
            //Toast.makeText(activity, "All unsubmitted information will be discarded", Toast.LENGTH_SHORT).show();
            LayoutInflater inflater = null;
            inflater = ( LayoutInflater )activity.
                    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v = inflater.inflate(R.layout.layout_back_press,null);
            AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
            builder.setView(v);
            dialog = builder.create();
            dialog.show();
            TextView cancel = (TextView) v.findViewById(R.id.txt_Cancel);
            cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.cancel();
                    //Toast.makeText(activity, "Feedback not sent", Toast.LENGTH_SHORT).show();
                }
            });
            TextView send = (TextView) v.findViewById(R.id.txt_Send);
            send.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.cancel();
                    FeedbackConcernsFragment.super.onStop();
                   // FeedbackConcernsFragment.onStop();
                    //Toast.makeText(activity, "Feedback sent", Toast.LENGTH_SHORT).show();
                }
            });

        }else {
            super.onStop();
        }

    }
  

E / AndroidRuntime:致命异常:主要                                                                过程:com.guideme,PID:23746                                                                android.util.SuperNotCalledException:Fragment   FeedbackConcernsFragment {22c43a48#2 id = 0x7f110159}没有调用   通过super.onStop()                                                                    在android.app.Fragment.performStop(Fragment.java:1873)                                                                    在android.app.FragmentManagerImpl.moveToState(FragmentManager.java:941)                                                                    在android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1167)                                                                    在android.app.BackStackRecord.popFromBackStack(BackStackRecord.java:718)                                                                    在android.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1496)                                                                    在android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:495)                                                                    在android.app.Activity.onBackPressed(Activity.java:2288)                                                                    在android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:179)                                                                    在com.guideme.activities.MainActivity.onBackPressed(MainActivity.java:352)                                                                    在android.app.Activity.onKeyUp(Activity.java:2266)                                                                    在android.view.KeyEvent.dispatch(KeyEvent.java:2724)                                                                    在android.app.Activity.dispatchKeyEvent(Activity.java:2496)                                                                    在android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:541)                                                                    在android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)                                                                    在android.support.v7.app.AppCompatDelegateImplBase $ AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)

3 个答案:

答案 0 :(得分:1)

崩溃日志实际上告诉你问题:

  

android.util.SuperNotCalledException

主要生命周期功能必须始终调用其超级功能。所以只需添加

super.onStop();

作为方法的第一行,代码将起作用:)

PS:不要忘记删除else分支中的超级呼叫,因为不再需要了。

答案 1 :(得分:1)

你应该在onStop上调用super。

@Override
public void onStop() {
    super.onStop();
    // Your code here
} 

答案 2 :(得分:0)

在提出问题之前请做一些研究,这个问题已在这里得到答案: android.app.SuperNotCalledException: Activity did not call through to super.onStop()