1

This is more along the lines of an "Is this possible, and SHOULD I try it?" question. Making a fairly straight-forward app that gets JSON data from a server on every page. The data is pretty simple JSON, and pretty much the same format across all pages.

{
"userid": "stringid",
"name": "some-name",
"description": "some description",
"properties": {
    "id": {
        "badgeid": "stringid",
        "type": "string"
    },
    "name": {
        "description": "Name of the product",
        "type": "string"
    }
},
"required": [
    "id",
    "name",
    "price"
]

}

It just seems wasteful to me to create an entire Volley request for each group of data. I've gotten around it a bit by just making a function and passing in common things like URL. But, I still have this same function on every single activity...

What I'm contemplating is just making a class, say "JSONObject GoGetJSON(String URL)" and have it return a JSONObject. This I can call... JSONObject test = new GoGetJSON("http://blah.com");

Then just use test as I like. Then I can include the encryption of the data string and all the other bells and whistles inside of that one class, rather than repeating work on each page. And if this is possible, I could create a custom adapter to filter out/backfill some of the "extra" data that might come across on the calls where all info isn't needed.

My concern is that by doing it this way, I'm essentially "breaking" the async task advantage, since it's waiting on the class, which is asyncing the volley request. Also would this also break the request queue?

Now, I'm still learning OOP, Java, and programming in general, so I'd just like to know what you more experienced programmers thought. Is it a worthwhile venture? Or am I barking up the wrong tree? I can see the advantage of portability if it works...I've tried googling a bit, but every example I see they are adding the volley directly for each request. I appreciate any feedback and help!

1 Answer 1

0

My concern is that by doing it this way, I'm essentially "breaking" the async task advantage, since it's waiting on the class, which is asyncing the volley request. Also would this also break the request queue?

User can any time cancel your request when moving out that particular Activity or while switching fragments. Every request is added in a queue and no matter how you design if your volley queue is same for every request it will work the same.

In my opinion network hits should be controlled from the one place, it will make you life much much better.

Try this site for reference http://www.michenux.net/android-volley-and-gson-tutorial-797.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.