Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>first you declare your parent class with all common behavior</p> <pre><code>public abstract class MyAbstractTask extends AsyncTask&lt;String, String, String&gt; { protected void someMethod() { //note that i change private to protected final RestAdapter restAdapter = new RestAdapter.Builder().setServer("http://10.0.2.2:8080").build(); final MyTaskService apiManager = restAdapter.create(MyTaskService.class); } } </code></pre> <p>then, you extend it with every task</p> <pre><code>public class MyTask extends MyAbstractTask { //your someMethod() is available from everywhere in your class } public class MyOtherTask extends MyAbstractTask { //your someMethod() is available from everywhere in your class } </code></pre> <hr> <p>but i dont know where you are using restAdapter and apiManager, and if the actually need to be created once per task, since probably you can create it outside of these tasks. </p> <p>If you create them outside, and then you need to use something inside your task, it is also good to have in mind the <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="noreferrer">Dependency_injection</a> pattern.</p> <hr> <p>Also, you should avoid hardcoding values in your classes, like <code>http://10.0.2.2:8080</code> </p> <p>You should use at least a <code>final static final String server= "http://10.0.2.2:8080"</code> and then use that, or better, use a setter or the constructor in the most inner class, and set tha values from the activity or the main controller. </p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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