How do I start a service from my Interactor using the MVP pattern in android?

前端 未结 1 1222
不知归路
不知归路 2021-02-08 02:50

I\'m following the Model View Presenter (MVP) pattern similar to Antonio Leiva\'s example found here: antoniolg/github.

I\'ve been playing around with it quite a bit and

1条回答
  •  遇见更好的自我
    2021-02-08 03:32

    Define class for example My App extends Application and define method like getAppInstance returns Application object and then add name attribute of this class to Applicqtion Tag in Manifest then call this method inside your use case to get context object and start your service

    public class MyApp extends Application {
    
        private MyApp instance;
    
        @Override
        public void onCreate() {
            super.onCreate();
    
            instance = this;
    
        }
    
        @Override
        public void onTerminate() {
            super.onTerminate();
    
            instance = null;
        }
    
        public MyApp getInstance(){
            return  instance;
    
        }
    }
    

    0 讨论(0)
提交回复
热议问题