Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api dealing with outdated RequestQueue #87

Merged
merged 2 commits into from
Aug 14, 2014
Merged

Conversation

hegazy
Copy link
Contributor

@hegazy hegazy commented Aug 12, 2014

The issue
If we search once or more, then click back, navigate to the app again, and try to search again, no callback methods get called.

why?
If we click back from the activity the API object still the same because it's a static object
and if we navigate again to the activity, we are creating a new RequestQueue in the onCreate() of the FlickrSearchActivity, but in Api.get(requestQueue) the API object is not null so here we are dealing with two request queues and the callback functions is never called.

If we click back from the activity the API object still the same because it's a static object
and if we navigate again to the activity, we are creating a new RequestQueue, but in Api.get(requestQueue) the API object is not null so here we are dealing with two request queues and the callback functions is never called.
@sjudd
Copy link
Collaborator

sjudd commented Aug 13, 2014

Another nice catch, thanks!

Let's solve this slightly differently though. Instead of passing in the request queue to the api, lets have the api own and create its own RequestQueue in its constructor. That way it doesn't have to worry about other people invalidating its dependency.

That would mean we could just pass in a context to obtain the api, which is nicer than the way I have it now anyway. Maybe something like:

public static Api get(Context context) {
...
}

protected Api(Context context) {
this.requestQueue = Volley.newRequestQueue(...);
}

@hegazy
Copy link
Contributor Author

hegazy commented Aug 14, 2014

You are right that saves us from recreating the requestqueue every time we create the activity

sjudd added a commit that referenced this pull request Aug 14, 2014
Api dealing with outdated RequestQueue
@sjudd sjudd merged commit e3524cc into bumptech:master Aug 14, 2014
@sjudd
Copy link
Collaborator

sjudd commented Aug 14, 2014

Great thanks for catching and fixing this!

@hegazy
Copy link
Contributor Author

hegazy commented Aug 14, 2014

That's my first contribution to an open source project.
Thanks alot

@sjudd
Copy link
Collaborator

sjudd commented Aug 15, 2014

Awesome, hopefully the first of many!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants