title: How to override an Activity's method in a Fragment
body: <p>I want to override a method present in an Activity through a Fragment which is added in the activity. </p>
  
  <p>I have following setup:</p>
  
  <p><em>BaseActivity</em></p>
  
  <pre><code>public class BaseActivity extends AppCompatActivity {
  
      // gets triggered whenever I set a toolbar title
      // from an Activity or Fragment
      public boolean shouldLimitToolbarCharacters () {  
          return true;
      }
  }
  </code></pre>
  
  <p><em>BaseFragmentActivity</em></p>
  
  <pre><code>public class BaseFragmentActivity extends BaseActivity implements ToolbarBehaviour {
  
      // override from BaseActivity and from ToolbarBehaviour
      @Override
      public boolean shouldLimitToolbarCharacters () {
  
          // instead send it to fragment somehow
          return true;
      }
  }
  </code></pre>
  
  <p><em>ToolbarBehaviour</em></p>
  
  <pre><code> // implemented by BaseFragmentActivity above
   interface ToolbarBehaviour {
       boolean shouldLimitToolbarCharacters();
   }
  </code></pre>
  
  <p><em>BaseFragment</em></p>
  
  <pre><code>public class BaseFragment extends Fragment {
  
      @Override
      public void onAttach (Context context) {
  
          if (context instanceof ToolbarBehaviour) {
  
              ToolbarBehaviour toolbarBehaviour = (ToolbarBehaviour) context;
  
              // ?? now what
          }
      }
  }
  </code></pre>
  
  <p>How do I override <code>BaseFragmentActivity</code>'s <code>shouldLimitToolbarCharacters()</code> from <code>BaseFragment</code> or its sub-fragments?</p>
  
  <p>Whenever I trigger <code>shouldLimitToolbarCharacters()</code> from a sub-fragment of <code>BaseFragment</code>, it should use sub-fragment's provided overridden method for <code>shouldLimitToolbarCharacters()</code>.</p>
  
  <p>Thanks.</p>