rest - How to separate application logic from network layer in Android using Retrofit 2 -
i new in android , retrofit , facing 1 problem.
i want have lets "servercommunication" class (singelton) retrofit magic done , have public methods rest calls done.
i want use "servercommunication" instance in activities call rest service, thats it. application logic should done in activity. way activity login calls method login(pojorequest) in "servercommunication) actual rest call via retrofit framework done , pojoresponse returned. activity doesn't care rest communication while servercommunication doesn't care logic should applied response rest service since.
with retrofit 2 not understand how can block activity wait response retrofit , how can returned. well, might think can use callback methods in activity methods can called servercommunication" in onpostexecute() apply logic based on data response. it's think should simpler approach.
well, clarify mess above imagine simple case: have data in main activity, pass data communication class rest call done , response received. response must validated in order continue. , want validation done in main activity , not in communication class.
what pattern in android retrofit2 ?
thank in advance
what do:
- create interface (where have rest methods - & post etc)
- create class actual calls corresponding methods (refer interface rest methods). call serviceapiimplementor. create retrofit adapter.
- in activity, create instance of implementor class , call methods , pass expected arguments.
- after calling methods, should show progress dialog let user know going on.
- when onresponse or onfailure method called, use event pattern (eventbus library?) notify activity network operation has been completed. once activity has received notification, should dismiss progress dialog , update ui accordingly - newly received data or completed operation (expected outcome).
i hope helps closer trying achieve!
Comments
Post a Comment