samedi 28 février 2015

Networking app architecture

I'm building an android app similar to a facebook app, aimed to display various information stored in a database. I'm using on the server-side a REST API, which returns responses based on various POST requests, with a facebook token authentification.


And on the client-side, I'm using the volley library to deal with network requests. I've tried numerous possibities but I'm searching for the most elegant way of communicating with the server, and since this is a trivial case, I thought you could maybe help me with this one...


Since I'm always checking fb tokens, and making similar POST requests, I considered adding a Connexion objet, which creates a volley request when prompted with an execute(POST parameters...); method, and calls a callback method when the response has arrived.


But I'm struggling to decide whether I should create a SessionManager object (Singleton or not ?) which can process ALL the data from session related responses (like check login, login...) based maybe on codes (for example Error 5xx for every type of response), and DO the intents.


Or I should process these responses in every activity, and do the intents there. Knowing they can maybe repetitive. In short, I'm looking for a best practice to apply when the app has to process common responses, and not so uncommon responses for example. Keep all the logic in the activities ? Create objects ? Don't hesitate to post your opinion on the subject !


Thank you very much.


EDIT : Ended up using a Connexion object to process all the requests (with volley). As for the Intents, I kept all that logic in the activities and haven't used another controller. The result was not ugly. Mainly because I used a secondary route which does the authentification, so the server ALWAYS responds with a big error if you're an evil hacker.


Aucun commentaire:

Enregistrer un commentaire