Is the rest client app design approach in google io 2010 still up to date?
Asked Answered
K

1

9

two years past, there comes fragment, intent service, cursor loader. Is the approach still up to date, or is there any better or mature pattern to design an android rest client, especially compare to the option B (I don't have the privilege to post image, instead the image could be found from this post).

I know the content provider part is essential. what about the service helper and service component? Up till now, the startService method is a nature of Context or its subclasses. which means the service helper would be an activity. So is it elegant to initiate an activity from a content provider, or should it be initiate from the activity on the top.

  • for those of you who digged into the google io 2011 iosched app source code, will you consider the static class SyncStatusUpdaterFragment in HomeActivity as the service helper, though it couldn't start the SyncService, but it does listen to the call back from SyncService and trigger refresh of UI. So could it be seen as a variance of the Virgil Dobjanschi's approach?

There comes service, intent service, asyncTask and thread. In my opinion, the intent service is suitable for sync of mega pack of data from remote server. That why they use it in the iosched. But the common scenario is that only a part of items will be synchronized with the remote server. So the intent service is too heavy. even the service approach. could we just use the asyncTask or thread in the content provider or some component of that to accomplish this kind of task. Or is there any convincing reason to use the service, and go through the service helper-service-processor path. I am talking about a serious application.

so what's you opinion?

Kemme answered 1/5, 2012 at 6:39 Comment(1)
I'm too new to android / REST development to be able to answer your question, and I have difficulties coming up with a good architecture for my app myself, but maybe the following link might help (there's part two as well): neilgoodman.net/2011/12/26/…Trajan
I
2

So is it elegant to initiate an activity from a content provider, or should it be initiate from the activity on the top.

You'll never ever initiate an activity from the content provider. Everything should start from your activity, whether that's a AsyncTask, Service, or Content Provider request...

AsyncTasks are generally a poor choice. They're simply flawed when it comes to dealing with configuration changes (i.e. screen orientation change). Loaders are the solution to this, but the difficult part is wrapping that together with your network calls. One solution is to build the network calls from a custom loader (subclassing AsyncTaskLoader).

However, in my case, I followed the 2010 Google IO presentation. Built a class, ServiceHelper, to manage requests to the server in a Service object (which launches threads to perform network queries). The ServiceHelper manages the ResultReceivers which can be created from the calling Activity. This allows the activity to listen to events from the Service request such as when the query starts and finishes (or when it errors out). These threads will call their network queries and then store the resulting data in a ContentProvider (for caching and to use across multiple Activities if necessary).

At the same time, I have a CursorLoader on the Activity that listens to the endpoint which the network thread will write to. Obviously there's a lot of middle ground to work out yourself.. such as your caching policy and the overhead for such an implementation. But that really depends on the app you're building and the API you're integrating with.

So yes, I think that the 2010 presentation is still valid.. there were a lot of vague areas of his presentation and the continues today. You'll have to still work out a design that works for your app

Hopefully, my thoughts will help you get started..

Inverness answered 14/7, 2012 at 6:18 Comment(2)
How did you work out the flags for the resources in the database? The guy doing the presentation is kind of vague on that subject and keeps changing the meaning for the flags.Temporal
Oops, my apologies for replying to this so late, I just saw it now. It's been awhile since I watched the video, but I suspect that you're talking about flags to determine whether or not the data is still valid? I think that would depend on the API you're using and the cache policy you have.Inverness

© 2022 - 2024 — McMap. All rights reserved.