otak info official Logo   
OTAK.INFO
Personal Blog

Hariyanto Lim

정길상 / 鄭吉祥
Home   Last Posts  
 
Please login to see more topics and discussion categories.
 
goto main category list >> Software programming >> Android

Title : How to use parse.com for Android
Total Reply : 0
Total View : 1848


Harry
Harry
Total thread: 131
Total reply: 50

Post #150
How to use parse.com for Android
  1. Register account in parse.com, get the "ApplicationId" and "ClientKey"
  2. Copy 2 jars ("bolts-android-1.1.3.jar" and "parse-1.7.1.jar") to project's "libs" folder
  3. Init the parse.com library in Activity.onCreate(), such as:
    '
    '.str_replace('
    ', ' ', '
    Parse.initialize(this, ParseApplicationId, ParseClientKey);
    ').'
    '
  4. To query data, example code snippet:
    '
    '.str_replace('
    ', ' ', '
    showProgressBar(true);

    ParseQuery<ParseObject> query = ParseQuery.getQuery("myClass");
    query.whereEqualTo("deviceId", deviceId);
    query.findInBackground(new FindCallback<ParseObject>() {
    @Override
    public void done(List<ParseObject> foundList, ParseException e) {
    if (e == null) {
    int iTotalRow = foundList.size();
    Log.d(TAG, "Retrieved " + iTotalRow + " rows");

    if(iTotalRow < 1) {
    Log.d(TAG, "device is NOT registered yet");

    // deviceId is not found == not register
    registerDevice();
    } else {
    Log.d(TAG, "device already registered");
    }
    } else {
    Log.e(TAG, "Error: " + e.getMessage());
    registerDevice();
    }

    showProgressBar(false);
    }
    });
    ').'
    '
  5. To store data, example code snippet:
    '
    '.str_replace('
    ', ' ', '
    showProgressBar(true);

    ParseObject deviceObject = new ParseObject("myClass");
    deviceObject.put("deviceId", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_ID));
    deviceObject.put("deviceScreenSize", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_SCREEN_SIZE));
    deviceObject.put("deviceScreenWidth", HSharedPreferences.getIntData(MainActivity.this, HSharedPreferences.KEY_DEVICE_SCREEN_WIDTH));
    deviceObject.put("deviceScreenHeight", HSharedPreferences.getIntData(MainActivity.this, HSharedPreferences.KEY_DEVICE_SCREEN_HEIGHT));
    deviceObject.put("deviceMACAddress", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_MAC_ADDRESS));
    deviceObject.put("deviceModel", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_MODEL));
    deviceObject.put("devicePhoneNumber", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_PHONE_NUMBER));

    deviceObject.saveInBackground(new SaveCallback() {
    @Override
    public void done(ParseException e) {
    if(e == null) {
    Log.d(TAG, "save completed");
    } else {
    Log.e(TAG, "save failed: " + e.getLocalizedMessage());
    }

    showProgressBar(false);
    }
    });
    ').'
    '


NOTE: FREE usage for parse.com has limitation, one of them is 30 operations per seconds, if we want to get more operations then we must pay.
Falling in love with the world

Write : 2015-01-07 14:25:29
Last edit : 2015-01-07 14:35:25

If you want to create a new reply then please login first.



www.OTAK.INFO
Since 19 January 2007
Page hit : 858,723

Code update 24th June 2013
Brain is a very capable to solve big problems
but requires constant reminders about how to.
peace bird