Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For my point of view the best solution here is to delegate logic to some class, let's call it <code>CustomActivityLogic</code>.</p> <p>Also you need to create common interface (<code>CustomActivity</code>) for your activities if you want to access some data or methods of activity classes from your logic class.</p> <p>To call protected virtual overridden methods there are two solutions: </p> <ul> <li>call method of supper from overridden method</li> <li>make a new method in subclass and call super method from this new method. Call new method from shared logic.</li> </ul> <p><strong>CustomActivity.java</strong></p> <pre><code>public interface CustomActivity { void someMethod(); } </code></pre> <p><strong>Activiti.java</strong></p> <pre><code>import android.app.Activity public class Activiti extends Activity implements CustomActivity { private CustomActivityLogic logic = new CustomActivityLogic(); public void someMethod() { /***/ } public void myNewMethod() { logic.myNewMethod(this); } @Override protected void onCreate(Bundle savedInstanceState) { logic.onCreate(this, savedInstanceState); // call shared logic super.onCreate(savedInstanceState); // call super } } </code></pre> <p><strong>FragmentActivitii.java</strong></p> <pre><code>import android.support.v4.app.FragmentActivity; public class FragmentActivitii extends FragmentActivity implements CustomActivity { private CustomActivityLogic logic = new CustomActivityLogic(); public void someMethod() { /***/ } public void myNewMethod() { logic.myNewMethod(this); } @Override protected void onCreate(Bundle savedInstanceState) { logic.onCreate(this, savedInstanceState); // call shared logic super.onCreate(savedInstanceState); // call super } } </code></pre> <p><strong>CustomActivityLogic.java</strong></p> <pre><code> public class CustomActivityLogic { public void myNewMethod(CustomActivity activity) { /*...*/ } public void onCreate(Activity activity, Bundle savedInstanceState) { /* shared creation logic */ } } </code></pre> <p><strong>Approach with making onCreate available to call from outside via <code>CustomActivity</code> interface</strong></p> <p><strong>CustomActivity.java</strong></p> <pre><code>public interface CustomActivity { void someMethod(); void onCreateSuper(Bundle savedInstanceState); } </code></pre> <p><strong>Activiti.java</strong></p> <pre><code>import android.app.Activity public class Activiti extends Activity implements CustomActivity { private CustomActivityLogic logic = new CustomActivityLogic(); public void someMethod() { /***/ } public void myNewMethod() { logic.myNewMethod(this); } @Override protected void onCreate(Bundle savedInstanceState) { logic.onCreate(this, savedInstanceState); // call shared logic } public void onCreateSuper(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // call super } } </code></pre> <p><strong>FragmentActivitii.java</strong></p> <pre><code>import android.support.v4.app.FragmentActivity; public class FragmentActivitii extends FragmentActivity implements CustomActivity { private CustomActivityLogic logic = new CustomActivityLogic(); public void someMethod() { /***/ } public void myNewMethod() { logic.myNewMethod(this); } @Override protected void onCreate(Bundle savedInstanceState) { logic.onCreate(this, savedInstanceState); // call shared logic } public void onCreateSuper(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // call super } } </code></pre> <p><strong>CustomActivityLogic.java</strong></p> <pre><code> public class CustomActivityLogic { public void myNewMethod(CustomActivity activity) { /*...*/ } public void onCreate(CustomActivity activity, Bundle savedInstanceState) { /* shared creation logic */ activity.onCreateSuper(savedInstanceState); // call-back super } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload