Skip to content

Instantly share code, notes, and snippets.

@Bahaaib
Created July 31, 2016 10:16
Show Gist options
  • Select an option

  • Save Bahaaib/59a4765b8d7e2c3a3c2ceae60bf39071 to your computer and use it in GitHub Desktop.

Select an option

Save Bahaaib/59a4765b8d7e2c3a3c2ceae60bf39071 to your computer and use it in GitHub Desktop.
How to search for a specific query on DB with criteria instead of Id
package com.parse.starter;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.ParseAnalytics;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.SaveCallback;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseQuery<ParseObject> query = ParseQuery.getQuery("Score");
query.whereEqualTo("username", "ralphie"); // Look for results with these criteria instead of inserting Id each time.
query.setLimit(1); // Only need the first result
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) { //Try to find the results on DB and arrange them into A List of ParseObjects
if (e == null) {
if (objects.size() > 0) {
objects.get(0).put("score", 250); //Handle the first result and modify the score query value to 250
objects.get(0).saveInBackground(); //send data with no Feedback
}
}
}
});
ParseAnalytics.trackAppOpenedInBackground(getIntent());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment