title: In Sub-Fragment , When webview can not go back then how to redirect to Main-Fragment or Home-Fragment
body: <p><strong>In my app I had create a Main Fragment with 2 Buttons, each Button has different fragment with different webview. This is my Sub-Fragment's Code, I am new here so forgive me for my mistakes.</strong></p>
  
  <pre><code>public class SubFragment extends Fragment {
  
      private WebView webView;
  
  
      public SubFragment() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_sub, container, false);
  
          webView = (WebView) view.findViewById(R.id.webView);
          webView.setWebViewClient(new WebViewClient());
          webView.getSettings().setJavaScriptEnabled(true);
          webView.loadUrl("https://www.google.com/");
          webView.getSettings().setLoadWithOverviewMode(true);
          webView.getSettings().setUseWideViewPort(true);
          WebSettings webSettings=webView.getSettings();
          webSettings.setJavaScriptEnabled(true);       
  </code></pre>
  
  <p><strong>Here is code of goBack. I just want to redirect on Main Fragmnet when webview can not goBack</strong> </p>
  
  <pre><code>       webView.canGoBack();
         webView.setOnKeyListener(new View.OnKeyListener() {
  
              public boolean onKey(View v, int keyCode, KeyEvent event) {
                  if (keyCode == KeyEvent.KEYCODE_BACK
                          &amp;&amp; event.getAction() == MotionEvent.ACTION_UP
                          &amp;&amp; webView.canGoBack()) {
                      webView.goBack();
  
                      return true;
                  }
  
                  return false;
              }
          });
  
     return view;
  
    }
  
  }
  </code></pre>