2017-08-25 54 views
-3
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:片段 FeedbackConcernsFragment {22c43a48#2的ID = 0x7f110159}沒有通過在android.app.Fragment.performStop(Fragment.java:1873) 在android.app.FragmentManagerImpl.moveToState(FragmentManager.java:941) 在android.app.FragmentManagerImpl致電 到super.onStop() .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) at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:179) at com.guideme.activities.MainActivity.onBackPressed(MainActivity.java: 352) at android.app.Activity.onKeyUp(Activity.java:2266) at android.view.KeyEvent.dispatch(KeyEvent.java:2724) at android.app.Activi在android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)上android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:541) 上的ty.dispatchKeyEvent(Activity.java:2496) 在android.support.v7.app.AppCompatDelegateImplBase $ AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)編碼的onStop崩潰應用

+1

的可能的複製[android.app.SuperNotCalledException:活動並未通過調用super.onStop ()](https://stackoverflow.com/questions/9397020/android-app-supernotcalledexception-activity-did-not-call-through-to-super-onst) – Torben

回答

1

的系統崩潰日誌實際上告訴了你的問題:

android.util.SuperNotCalledException

主生命週期函數必須始終調用其超級函數。所以只需添加

super.onStop(); 

在方法的第一行和代碼將工作:)

PS:不要忘了刪除else分支超級調用,因爲這是沒有必要了。

1

你應該在onStop中調用super。

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

如果信息不是空的,我不想致電super.on停止 –

+0

@JarinRocks;錯誤告訴你,你必須調用super.onStop,如果你選擇覆蓋該方法,你沒有選擇 – 0xDEADC0DE

+0

ok謝謝@ 0xDEADC0DE –