Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialevgeniylischuk
5,265 PointsFindInBackground (Parse.com) doesn't work with fragments
Good afternoon. I've tried to modify Ribbit project to use fragments and faced the problem that method done() doesn't start at all when is called from fragment. (FindInBackground( new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> list, ParseException e) {.....} And I had to use find() instead of findInBackground Could you, please, help me find the way to use exactly Callback because as I understood - it's not a good idea to work with queries in the UI thread.
evgeniylischuk
5,265 Points'''java queryParse.findInBackground(new FindCallback<ParseUser>() {
// @Override // public void done(List<ParseUser> list, ParseException e) {
// if (e == null) { // mFriends = list; //
// int i = 0; // mFriendsNames = new String[mFriends.size()]; // for (ParseUser user : mFriends) {
// mFriendsNames[i] = user.getUsername(); // i++; // // } // // } else { // Log.i("Friends.onResume", e.getMessage()); // AlertDialog.Builder builder = new AlertDialog.Builder(mContext); // builder.setTitle("Friends list error"); // builder.setMessage("An error: " + e.getMessage() + " has occured"); // builder.setPositiveButton("Ok", null); // AlertDialog dialog = builder.create(); // dialog.show(); // } // // } // // }); '''
evgeniylischuk
5,265 PointsAnd when I run this code done() method never get called. I saw on stackflow one post that there is a problem exactly with calling FindInBackground() from fragments but no solution and it was date 2014year.
5 Answers
TheBigoso /\
3,217 PointsHi evgeniylischuk,
I made this video for you. This Video explains how to implement parse into an existing project. let me know if you need any help.
https://www.youtube.com/watch?v=KkvWHaIHFt0
TheBigOso
TheBigoso /\
3,217 Pointscheck this out you can make your code look nice by using this at the top tilda tilda tilda Java and this at the end tilda tilda tilda . every time i use the tilda thats above the tab button on your keyboard it rems it out.
queryParse.findInBackground(new FindCallback() {
@Override
public void done(List list, ParseException e) {
if (e == null) { // mFriends = list;
int i = 0; // mFriendsNames = new String[mFriends.size()];
for (ParseUser user : mFriends) {
mFriendsNames[i] = user.getUsername();
i++;
}
}
im also making a video for you that i will post.
thx
oso
evgeniylischuk
5,265 PointsThank you very much. With tilda it really looks much better:))
queryParse.findInBackground(new FindCallback<ParseUser>() {
int started = 1;
@Override
public void done(List<ParseUser> list, ParseException e) {
if (e == null) {
mFriends = list;
int i = 0;
mFriendsNames = new String[list.size()];
for (ParseUser user : mFriends) {
Log.i("Parse",user.getUsername() + " i = " + i);
mFriendsNames[i] = user.getUsername();
i++;
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Friends list error");
builder.setMessage("An error: " + e.getMessage() + " has occured");
builder.setPositiveButton("Ok", null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
TheBigoso /\
3,217 PointsRight on now Its much more readable
evgeniylischuk
5,265 PointsI watched your video. Thanks. Did I understood you right, that I should try to setup Parse connection as existing project instead of new one? Will it solve problem with findInBackground() in fragment?
TheBigoso /\
3,217 PointsYeah how i went about it, wherever you put parse for the video, you can do the same thing to your existing project. But I don't know if it will fix your background problem. As i don't have the project in front of me. What i would do is use the project we just made with the sliding tabs. Then combine your old project with the new one. I would do this by re watching all the videos . At the same time i would make sure the program complies after every video. So when something is broken with your program you know its was during the last few videos.
TheBigOso
TheBigoso /\
3,217 PointsTheBigoso /\
3,217 PointsCan i see your code