I have an application that insert & retrieve data from parse. but i need to insert multiple entry in a single task under one id. I can do that using loop but is there anyway to insert multiple entry at once? For an example: I have an user id "ABC" and this user entry some data like : data-1(abc, Ny, water), data-2(xyz,bristol, air), data-3( qwe, ca, fire). how can i insert all 3 data under ABC id altogether into parse?
ParseObject userOrder = new ParseObject("tableName");
userOrder.put("userId", userId);
userOrder.put("data",data);
userOrder.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null){
//successfully data inserted
}
else {
//there is an error in data insertion }
}
});
Yes you can do that using saveAllinBackground
final List<ParseObject> parseTaskObjects = new ArrayList<>();
for (TaskResponse taskResponse : ((MainApplication)(getApplicationContext())).getTaskResponses()) {
ParseObject parse_assignment = new ParseObject("TaskResponse");
parse_assignment.put("TaskID", list.get(((MainApplication) (getApplicationContext())).getTaskResponses().indexOf(taskResponse)));
parse_assignment.put("AssignmentId", assignment);
if (taskResponse.getTaskType() == TaskType.LOCATION.ordinal()) {
parse_assignment.put("LocationResp", getParseGeoPointFromLatLng(taskResponse.getLocationResponse().latitude, taskResponse.getLocationResponse().longitude));
} else if (taskResponse.getTaskType() == TaskType.PICTURE.ordinal()) {
ParseFile file = new ParseFile("image.jpg", taskResponse.getPictureResponse());
file.saveInBackground();
parse_assignment.put("PicResp", file);
} else if (taskResponse.getTaskType() == TaskType.TAGS.ordinal()) {
parse_assignment.put("TagResp", taskResponse.getTagResponse());
} else if (taskResponse.getTaskType() == TaskType.TEXT.ordinal()) {
parse_assignment.put("TextResp", taskResponse.getTextResponse());
} else if (taskResponse.getTaskType() == TaskType.NUMBER.ordinal()) {
parse_assignment.put("NumResp", taskResponse.getNumberResponse());
}
parseTaskObjects.add(parse_assignment);
}
ParseObject.saveAllInBackground(parseTaskObjects, new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(Stint_task.this, "Stint Tasks Completed Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Stint_task.this, "Stint Failed", Toast.LENGTH_SHORT).show();
}
}
});
Related
Currently i have 2 users:
Tester1 and AnotherTester
I've been trying to create a public group channel using my Tester1
but whenever i try to create one.
It's not showing in my list using AnotherTester
Here is my code in creating public group channel
GroupChannelParams params = new GroupChannelParams()
.setPublic(true)
.setDiscoverable(true)
.setEphemeral(false)
// .addUserIds(users)
.setDistinct(false)
.setName(channelName);
GroupChannel.createChannel(params, new GroupChannel.GroupChannelCreateHandler() {
#Override
public void onResult(GroupChannel groupChannel, SendBirdException e) {
if (e != null) { // Error.
Toast.makeText(context, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
Logs.logError(e.getMessage());
retrySendConnection(context, String.valueOf(e.getCode()), e.getMessage());
return;
} else {
// inviteUser(groupChannel);
Logs.logData(groupChannel.getUrl());
Intent i = new Intent(MainActivity.this, channelChatActivity.class);
i.putExtra("channelUrl", groupChannel.getUrl());
startActivity(i);
}
}
});
So Tester1 is the one that created a public group channel
but when i switch to AnotherTester, it doesn't show the public group channel.
Here is my code in retrieving AnotherTester channels
GroupChannelListQuery channelListQuery1 = GroupChannel.createMyGroupChannelListQuery();
channelListQuery1.setIncludeEmpty(true);
channelListQuery1.next(new GroupChannelListQuery.GroupChannelListQueryResultHandler() {
#Override
public void onResult(List<GroupChannel> list, SendBirdException e) {
if (e != null) {
Logs.logError(e.getMessage());// Error.
return;
} else {
groupChannelList.addAll(list);
groupChannelAdapter = new groupChannelAdapter(context, groupChannelList);
initializeRecyclerView(channelAdapter);
}
}
});
i hope you can help me.
You need to do atleast one message in that , then it will show to another user. Please try once to send one message.
Please try this code :-
private void createGroupChannel(List<String> userIds, boolean distinct, final String toID) {
GroupChannel.createChannelWithUserIds(userIds, distinct, "tsg-chat-" + SessionUtils.getCurrentMemberId(this) + "-" + toID, "", "", new GroupChannel.GroupChannelCreateHandler() {
#Override
public void onResult(GroupChannel groupChannel, SendBirdException e) {
if (e != null) {
// Error!
return;
}
}
});
}
public void pictureQuery() {
friendsPic = new ArrayList<>();
for (int i = 0; i < friendsList.length(); i++) {
ParseQuery parseQuery = ParseQuery.getQuery("Data");
parseQuery.whereEqualTo("firstName", "John");
//parseQuery.whereEqualTo("userId",friendsID.get(i));
parseQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
String link = objects.get(0).get("picUrl").toString();
Bitmap bitmap = null;
try {
bitmap = task.execute(link).get();
friendsPic.add(bitmap);
} catch (Exception e1) {
e1.printStackTrace();
}
Log.i("FDA, done", friendsPic.toString());
} else {
Log.i("FD", "0002");
}
} else {
e.printStackTrace();
}
}
});
}
}
Hi guys,
I am trying to retrieve picture URL from parse server (stored as a string), originally I was trying to make a query using the Id, but also tried to hard code it using:
parseQuery.whereEqualTo("firstName", "John");
It always seems to go to the else statement of object.size() > 0 i.e.
Log.i("FD", "0002");
I think i've checked everything including:
size of friendsList ( for the for loop )
spelling, made sure that "Data", "firstName" and "John" are the same on Parse Server
The value of friendsID.get(i)
Tried to use findFirstInBackground instead (same issue)
I have also compared it with my other code for different data ( that works ) :
ParseQuery parseQuery = ParseQuery.getQuery("SportData");
parseQuery.whereEqualTo("id", mApp.getId());
parseQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
saveSportData(objects.get(0), false);
} else if (objects.size() < 1) {
saveSportData(null, true);
}
} else {
e.printStackTrace();
}
}
});
Any idea what am I doing wrong, or what may be causing it ?
Thanks a lot.
Retrieved data and stored in local database but while trying to pull relation from the local database I get empty list which indicates that the relation data is not pinned to the local database.
public void retrieveThreadListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.include("postedBy");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if(e == null)
{
// Query is successful now lets load data from parse
ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() {
#Override
public void done(ParseException e) {
if(e == null)
{
if(!isFinishing())
{
// TODO : Notify to refresh data
}
}
else
{
Log.d("DEBUG","ERROR PINNING DATA WITH EXCEPTION : "+e);
}
}
});
}
}
});
So how should I pin "relation" data to the local database ???
What is the best way to read comments which is a relation. shall I store them in local datastore or pull data in the background ??
make sure you enableLocalDatastore store in application class Parse.enableLocalDatastore(getApplicationContext());
Parse local data store will not work with cache policy. We can access relational data like below
private void getParseData() {
if (parseObjectId != null) {
mApp.show_PDialog(context, "Loading..");
ParseQuery<ParseObject> parseQuery = new ParseQuery<>("Profile");
parseQuery.getInBackground(parseObjectId, new GetCallback<ParseObject>() {
#Override
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
try {
newName = parseObject.getString("name");
newGender = parseObject.getString("gender");
newDOB.setTime(parseObject.getDate("dob"));
newTOB.setTime(parseObject.getDate("tob"));
newCurrentLocation = parseObject.getParseObject("currentLocation");
newPOB = parseObject.getParseObject("placeOfBirth");
if (newName != null) {
displayName.setText(newName);
}
if (newGender != null) {
gender.setText(newGender);
}
if (newDOB != null) {
DateFormat df = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("UTC"));
String subdateStr = df.format(newDOB.getTime());
datePicker.setText(subdateStr);
}
if (newTOB != null) {
DateFormat df = new SimpleDateFormat("hh:mm a", Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("UTC"));
String subdateStr = df.format(newTOB.getTime());
timepicker.setText(subdateStr);
}
if (newPOB != null) {
placeOfBirth.setText(newPOB.fetchIfNeeded().getString("name")
+ ", " + newPOB.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newPOB.getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name"));
}
if (newCurrentLocation != null) {
currentLocation.setText(newCurrentLocation.fetchIfNeeded().getString("name")
+ ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name"));
}
} catch (ParseException e1) {
e1.printStackTrace();
}
} else {
e.printStackTrace();
}
mApp.dialog.dismiss();
}
});
} else {
getActivity().finish();
}
}
I'm trying to read from parseObject. I have a class over there and I'm trying to get the messages from there but I get only the last message that is sent from the device.
So if I send two messages only the last one is sent.
Can anyone help me?
This is my code:
ParseQuery<ParseObject> query = ParseQuery.getQuery("SmsTable");
query.whereEqualTo("deviceId", android_id);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, com.parse.ParseException e) {
if (e == null) {
for (ParseObject smsObject : objects) {
Date time = (Date) smsObject.get("date");
myMsg = (String) smsObject.get("message");
usrNum = (String) smsObject.get("phoneNumber");
//happend = (boolean) smsObject.get("happend");
result = time;
}
} else {
}
}
});
if (System.currentTimeMillis() >= result.getTime()&& happend == false) {
// count++;
sendMsg2(myMsg, usrNum);
happend = true;
}
Use this
for (ParseObject smsObject : objects) {
Date time = (Date) smsObject.get("date");
myMsg = (String) smsObject.get("message");
usrNum = (String) smsObject.get("phoneNumber");
//happend = (boolean) smsObject.get("happend");
result = time;
if (System.currentTimeMillis() >= result.getTime()&& happend == false) {
// count++;
sendMsg2(myMsg, usrNum);
happend = true;
}
}
I hope this will solve your problem
It seems that myMsg and usrNum are not an Array or a List.
You only call sendMsg2(myMsg, usrNum) once, after the loop has ended. That is why you only get the last message.
Move sendMsg2(myMsg, usrNum) into the loop.
The problem seems to be that you have located your sendMsg2() outside of both - the callback scope and the loop scope. If you want to have all of your messages being sent you have to put sendMsg2() inside of the loop.
ParseQuery<ParseObject> query = ParseQuery.getQuery("SmsTable");
query.whereEqualTo("deviceId", android_id);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, com.parse.ParseException e) {
if (e == null) {
for (ParseObject smsObject : objects) {
Date time = (Date) smsObject.get("date");
myMsg = (String) smsObject.get("message");
usrNum = (String) smsObject.get("phoneNumber");
//happend = (boolean) smsObject.get("happend");
result = time;
if (System.currentTimeMillis() >= result.getTime()&& happend == false) {
// count++;
sendMsg2(myMsg, usrNum);
happend = true;
}
}
} else {
}
}
});
I have 37 files to download and I wanted to show my progress bar complete in 100%. how can I set that my last file will equal to 100%.. sorry for my english. thanks in advance..
querySound.findInBackground(new FindCallback<ParseObject>() {
#SuppressWarnings("unused")
#Override
public void done(List<ParseObject> objects, ParseException e) {
Log.d("OBJECTS MP3", ""+objects.toString());
if (objects == null) {
Toast.makeText(ParseStarterProjectActivity.this,"Something is Wrong!", Toast.LENGTH_LONG).show();
} else {
final int adder = 100 / objects.size();
for(ParseObject po : objects){
ParseFile sounds = (ParseFile) po.get("remindersSpanish");
final String filenames = sounds.getName().substring(37, sounds.getName().length());
Log.d("OBJECTS NAME", filenames);
sounds.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data,ParseException e) {
Log.d("OBJECTS DATA", ""+data);
if (e == null) {
saveMp3(filenames, data);
counter = counter + adder;
} else {
e.printStackTrace();
}
prgBar.setProgress(counter);
counterPrg.setText(counter+"/"+prgBar.getMax());
}
});