Monday, June 17, 2013

dot42 and Parse

Parse allows you to store your app's data in the cloud. The Parse Quickstart let's you create a basic Parse Android app in minutes. We will walk through this Quickstart and make the necessary changes to make it work with dot42. It is assumed that you have signed up with Parse.

Create new dot42 project

First, create a blank dot42 Application Project from Visual Studio 2010 Professional, Visual Studio 2012 Professional or the SharpDevelop edition that is included in the dot42 download.


Parse Quickstart Guide

Login to your Parse account. If you haven't created an app yet, then Parse will make it very obvious how to do so. So I assume your first app as been created. Click 'Quickstart Guide' right after creating your app or click 'Quickstart' at the top of the dashboard.


Let's go through the Quickstart Guide as it appears on the Parse web site and take all the analog dot42 steps. We will number the steps similarly so it should be easy to match the Quickstart steps.

First you must choose your platform. Make the following selections: Android, Native and Existing project.




1. Download the SDK

Follow the "SDK files for existing Android projects (.zip)" link.

2. Import the zip file's contents into your existing Android project

Create a libs folder inside the dot42 project that we created at the very start. Copy "Parse-1.3.0.jar" from the zip archive the to the libs folder.

Right-click the Project node and select 'Add Jar Reference...".


The following dialog shows:


Browse to "Parse-1.3.0.jar" in the libs folder and hit OK. Reload the project if prompted. Compile the project to verify that the import went fine. The reference should now have been added like this:


3. Add the following using statement to your Activity:

using Com.Parse;
Call Parse.initialize from your onCreate methods to set your application id and client key:
Parse.Initialize(this, 
   "k1DM1............................d9RyrVu", 
   "etaQb............................SJfz7Yh");
Make sure to copy your own keys here! Also notice how the Initialize is captitalized.

4. Request appropriate permissions

Your app must request the "INTERNET" and "ACCESS_NETWORK_STATE" permissions:
[assembly: UsesPermission(
   Android.Manifest.Permission.INTERNET)]
[assembly: UsesPermission(
   Android.Manifest.Permission.ACCESS_NETWORK_STATE)]

5. Track statistics around application opens

Add the following to the onCreate method of your main Activity:
ParseAnalytics.TrackAppOpened(GetIntent());


After installing the SDK, copy and paste this code into your app, for example in your Application.onCreate:
ParseObject testObject = new ParseObject("TestObject");
testObject.Put("foo", "bar");
testObject.SaveInBackground();
Run your app. A new object of class TestObject will be sent to the Parse Cloud and saved. When you're ready, click the button below to test if your data was sent. It should look similar to this:





No comments:

Post a Comment