Thursday, August 23, 2012

Re: [android-developers] Best Practices for many calls to API

I use an async task and a listener interface on my activity/fragment.


So, I create an interface like this:

public interface SearchResultListener {
public void onSearchResults(Map<String, List<ContentListItem>> results);
}


Then my activity/fragment implements that interface:

public class SearchActivity extends Activity implements SearchResultListener {


Then make a task like this:

public SearchTitlesTask(SearchResultListener listener) {
this.listener = listener;
}


Then when I run the activity, it creates and executes the task like this:

new SearchTitlesTask(this).execute(query);

Then in the onPostExecute of the task, I do this:

protected void onPostExecute(LinkedHashMap<String,
List<ContentListItem>> results) {
if(null != listener){
listener.onSearchResults(results);
}
}

Larry


On Thu, Aug 23, 2012 at 10:53 AM, Christian Palomares (ShinjiDev)
<palomares.c@gmail.com> wrote:
> Hi
> I'm developing an Android App for an enterprise(just for smartphone, no
> tablet).
> This app needs to make many request to an API to fill 3 or 4 carrousels, the
> problem is that it takes too much time, i believe this happens because the
> request to the API are made sequentially. Is there any way to make
> concurrent request to an API to fill differents layouts???Or maybe a best
> practice for an Android app which needs to make too many API requests???
>
> Sincerely,
> Christian Palomares
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate