mercredi 14 juin 2017

The suitable way for avoiding static method (in Util class maybe) which use for updating UI

I'm beginner in Android, I read and see if use the static method in Util class for updating UI is not good for unit test. How do I avoid it in suitable way for maintaining code and unit test ?

Example:

class ActivityA {
    private View view;
    private MyListener myListener;
    public void downloadB() {
        Util.callDownloadLogicB(this, view, myListener);
    }
}

class ActivityB {
    private View view;
    private MyListener myListener;
    public void downloadB() {
        Util.callDownloadLogicB(this, view, myListener);
    }
}

class Util {
    public static void callDownloadLogicB(Context context, View view, MyListener listener) {
    // do something with view
    }
}

Aucun commentaire:

Enregistrer un commentaire