B4A Library Parse Library – Push Notifications and Cloud Storage

Parse service is shutting down: http://blog.parse.com/announcements/moving-on/

Overview


This library is a rather extensive overhaul of and update to Erels’ original Parse library.

Parse is a company that provides several services for mobile applications and has just been purchased by Facebook so it looks like it should continue to be a stable and reliable service.

You create an account on Parse.com and then create what they call “Applications” which would usually correspond with individual Android applications but don’t have to, so several different Android applications could access a common body of data in a single Parse application. Within Parse applications there are “Classes” of data which look much like a database table and contain ParseObjects which look like an individual row of data in a table.

Capabilities

The two major uses for this library are as follows

1) Providing cloud based data storage and retrieval for data held in the individual Parse Applications in a simple way including querying the stored data. No need to mess with HTTP and networking, it is all done for you in an object oriented fashion.

2) Supporting Push Notifications which can be instigated both from the Parse Web Dashboard of your Parse account and, if you have enabled it in the Dashboard for that Parse application, also from devices running the corresponding Android application. Push Notifications are sent in the context of the individual Parse Applications whose Android applications have registered to receive them but individual devices, or groups of devices, may be selectively targeted by using “Channels”.

Parse offer three levels of service, the first being free as long as you keep within their limits which are one million API Requests per month, one million Push Notifications per month and one Gigabyte of storage use. You can exceed these limits without upgrading to the next paid plan, which is presently 199 US dollars per month if you register a credit card. You can exceed these limits and be charged 7 US cents per one thousand excess API Requests, 20 UC cents per one thousand Pushes and 20 US cents per one Gigabyte of excess storage. There is information on your usage of all three available in your Parse Dashboard.

An API Request is a single network operation which are the ones that raise Basic4android events from the library.

The definition of the number of Pushes is “The total number of push notifications queued for delivery to a client device”. I may be being stupid but that seems ambiguous to me and I don’t understand whether that means that the total number of Push Notifications counts as each single message sent to lots of devices or as the total number of devices to which a single message is sent. I suspect the latter. If anyone knows definitively than please post and I will amend this paragraph.

The amount of storage used is obvious and needs no explanation.

Please read the Parse Android Guide, in the Parse.com Documentation section of their web site, for more information about how to use this library. The Parse Android API document might also be useful occasionally. The mapping of this library objects methods to those of the Java API are usually obvious.

All the operations which need to access the Parse online service are done asynchronously and raise events when complete whose parameters include a Success indication. If an error occurs Success will be False and a ParseException with a message describing the error will be placed in LastException. If necessary this should be processed in the event code as there is a possibility that a further error could occur in another asynchronous call that would overwrite the existing LastException.

Note that these asynchronous operations do not necessarily complete in the order in which they are invoked. To deal with this possibility a TaskID parameter is provided in each call that can be used, if required, to identify which of several possible method calls has just completed.

Installation instructions

In order to use this library you should sign up to Parse.com, go to your Dashboard and create a new Parse application called whatever you feel like calling it. You will need two keys, Application Id and Client Key, which you will find under the Settings for your application. Both are required and need to be copied to the appropriate Process Global variables in the demo.

You also need to download the Parse Android SDK from the Downloads section of the Parse.com web site. Inside the zip file you will find a file named Parse-1.2.4.jar or similar. Copy this to your Additional Libraries folder and rename it ParseNative.jar. Also put Parse.jar and Parse.xml from the demo archive in your Additional Libraries folder.

As detailed in the help for Parse. EnableNotifications in order for your application to receive Push Notifications you need to add the following to the Manifest Editor in your project.
B4X:
SetApplicationAttribute(android:name,"anywheresoftware.b4a.objects.ParseObjectWrapper$ParseApplication")

AddApplicationText(<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.USER_PRESENT" />
  </intent-filter>
</receiver>)

Version 1.1 of this library specified the Parse keys in a Parse.Initialize method. This method no longer exists in version 1.2 and later. This is because it it was called from within an Activity, but if Android killed your process and then tried to restart the Parse Service this failed because the service started without the activity being created and so was not initialised correctly. Initialisation now occurs on Application creation and requires the library Application class name to be registered in the manifest and the Parse keys to be specified as an xml resource. When the application is loaded you will see the values in the xml file echoed to the filtered logs.

You also need to place a file called res.xml in your project Objects/res/xml folder and make it read-only. The xml folder does not exist in the project archive but will be created at your first compile. The contents of res.xml should specify your Parse keys as follows
B4X:
<!--?xml version="1.0" encoding="utf-8"?-->
<data>
   <data1 value="YourParseApplicationAppID" />
   <data2 value="YourParseApplicationClientKey" />
</data>

The demo project is already set up to receive push notifications. Try sending one from your Parse Application using the Parse Dashboard.

Run the demo and have a play.

Issues

I have found that using IE10 to send a Push from the Parse Dashboard usually causes the Push to be sent twice, you will see this in the Dashboard list of pushes sent and also at the device and of course they both count towards your free total. Chrome appears to work correctly and sends only one. The work-around is obvious.

The Parse library starts a service called PushService to receive the Pushes and which you can see in Settings -> Apps -> Running -> ParseDemo. Prior to Parse SDK 1.2.4 sometimes this service stopped receiving Pushes and the Process needed to be stopped using a Task Manager and restarted. Parse SDK 1.2.5 should have fixed this.

EDIT:- Version 1.2 now posted. See post #6 for details.

EDIT:- Version 1.3 now posted. See post #13 for details.

EDIT:- Version 1.4 now posted. See post #17 for details.
 

Attachments

  • Parse1.4.zip
    43.2 KB · Views: 1,318
Last edited by a moderator:

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
I don't receive any error message. I posted the log and the phone show a message that ParseDemo crashed
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
If I use your app, what do I have to change in the AndroidManifest or into folder ParseDemo\Objects\res\xml\...?
 

Douglas Farias

Expert
Licensed User
Longtime User
Parsing code. 0.03
Compiling code. 0.16
Compiling layouts code. 0.00
Generating R file. 0.23
Compiling generated Java code. Error
B4A line: 81
po.put(\
javac 1.8.0
src\b4a\example\parse\main.java:383: error: cannot access ParseFile
_po.Put("File",(Object)(_pf.getObject()));
^
class file for com.parse.ParseFile not found
1 error

how to fix this? i dont make any changes on the code
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
I noticed that if I add this line to the manifest, the app crash

B4X:
SetApplicationAttribute(android:name,"anywheresoftware.b4a.objects.ParseObjectWrapper$ParseApplication")

I must modify it?

EDIT

If I delete it, I've got this error:

B4X:
LogCat connected to: 0123456789ABCDEFG
--------- beginning of /dev/log/main
-------- beginning of /dev/log/system
** Activity (main) Create, isFirst = true **
java.lang.RuntimeException: You must call Parse.initialize(context, oauthKey, oauthSecret) before using the Parse library.
    at com.parse.ParseUser.checkApplicationContext(ParseUser.java:1162)
    at com.parse.ParseUser.getCurrentUser(ParseUser.java:946)
    at com.parse.ParseUser.getCurrentSessionToken(ParseUser.java:1004)
    at com.parse.ParseAnalytics.createCommand(ParseAnalytics.java:229)
    at com.parse.ParseAnalytics.trackAppOpenedInBackground(ParseAnalytics.java:49)
    at com.parse.ParseAnalytics.trackAppOpened(ParseAnalytics.java:78)
    at anywheresoftware.b4a.objects.ParseObjectWrapper$ParseWrapper.TrackOpening(ParseObjectWrapper.java:448)
    at b4a.example.parse.main._activity_create(main.java:342)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at b4a.example.parse.main.afterFirstLayout(main.java:98)
    at b4a.example.parse.main.access$100(main.java:16)
    at b4a.example.parse.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)
    at android.app.ActivityThread.main(ActivityThread.java:5297)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)
 
Last edited:

stu14t

Active Member
Licensed User
Longtime User
I have a very basic question: Excuse me if it is dumb/basic I am new to both parse and b4aobject
I want to use parse backside to do a very simple thing, save and keep synced some set-points,
let's say 10 integers.
So I create a Parse object it and I put in my setpoints e.g. params.Put("setpoint1","5") ...
I can save it to the parse database, with params.Save("params",1)
This works fine, there it is in the parse dashboard, all very nice and easy.
Here is where I am stuck: I want to do 2 things
1: I want to update the object that is stored in the database, not add a new one, with a new unique objectID -- like update in SQL
2: I want to poll the server when the app loads and get the object into memory. -- can I use params.refresh to achieve this?
It seems like overkill to do a query where I just want to put and get data into a single object with fixed ID.
Seems like the most simple possible case but I'm not seeing how to do it.
Thanks,
Quentin

Quentin,

If you were to use the ParseUser object, a special object to deal with users to store your info, there is no need to run a query. After logging in the ParseUser object is always available and you can GET information straight to and from it. The ParseUser object is held in session from login to logout.

Now I know the ParseUser is not currently supported but it is only an extension of the standard Parse Object and you may be able to access the methods involved.
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Still having problem.. Please help :(
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hmm, just having a bit of difficulty with compiling the parse demo 1.4.

B4X:
Parsing code.                           0.01
Compiling code.                         0.02
   
ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code.                 0.00
Generating R file.                      0.06
Compiling generated Java code.          Error
B4A line: 81
po.put(\
javac 1.7.0_51
src\b4a\example\parse\main.java:383: error: cannot access ParseFile
_po.Put("File",(Object)(_v7.getObject()));
                                     ^
  class file for com.parse.ParseFile not found
1 error
Picked up _JAVA_OPTIONS:  -Xmx512M

The test file exists, I've copied over the parse jar, both including the native one and renamed it. Checked the manifest and made sure that the keys are in the res.xml file and it's read only.

Did I miss something?
 

derez

Expert
Licensed User
Longtime User
Looks like your class in parse is not called by the name you use in the application.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
oh, you mean the path to this example? I just downloaded and extracted it to my desktop. Where would I need to rename it?
 

derez

Expert
Licensed User
Longtime User
From the instructions in the first post:
In order to use this library you should sign up to Parse.com, go to your Dashboard and create a new Parse application called whatever you feel like calling it. You will need two keys, Application Id and Client Key, which you will find under the Settings for your application. Both are required and need to be copied to the appropriate Process Global variables in the demo.
If you have done this, you have a parse class and you should initialize parseobjects to this name.
For example, I have a class named Family, so I use this code to perform actions with it:
B4X:
...
Dim Addpo As ParseObject
Addpo.Initialize("Family")
...
 

Attachments

  • parse.png
    parse.png
    66.7 KB · Views: 214

derez

Expert
Licensed User
Longtime User
Yes, I added a picture showing how it looks on Parse.com
You can create fields and add data items in the parse application directly, and then try to work with it by your b4a application.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Thanks.

What do you do with the other files from the Parse -1.7.1 sdk?

I only copied parse -1.7.1.jar and renamed it to ParseNative.jar
 
Last edited:

merlin2049er

Well-Known Member
Licensed User
Longtime User
lol, I see where I made my mistake. I renamed the file ParseNative.jar.

It was actually ParseNative.jar.jar
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
I downloaded the latest parse.com sdk (v1.8) and I'm using B4A v4.00, it compiles, but crashes on launch.
 

QuentinLindh

Member
Licensed User
Longtime User
Quentin,

If you were to use the ParseUser object, a special object to deal with users to store your info, there is no need to run a query. After logging in the ParseUser object is always available and you can GET information straight to and from it. The ParseUser object is held in session from login to logout.

Now I know the ParseUser is not currently supported but it is only an extension of the standard Parse Object and you may be able to access the methods involved.
Thanks for that, I am trying it out-was busy with other things for a while
-Quentin
 

stu14t

Active Member
Licensed User
Longtime User
Is there any plans to extend the library to provide the full complement of Parse attributes?

I've now been working with Parse for over a year now and have seamlessly integrated it into C# desktop programs and PHP web applications and I'll be honest, my Java and understanding of how to wrap third party libraries is poor.

I'm building a suite of programs for industry and I'd love to be able to connect them all using Parse as the back end database.

The most important aspect I'm missing is the ParseUser object. This would help immensely or if someone could help in showing how to extend the current wrapper.
 

lagore

Active Member
Licensed User
Longtime User
I can get ParseDemo to compile and install but the app crashes as soon as it runs I suspect the problem maybe that the latest API (v1.8) has broken the library, in fact the API changed from v1.7. Does anybody have v1.6 or earlier that I could get to see if that sorts out the problem.
 

derez

Expert
Licensed User
Longtime User
I can get ParseDemo to compile and install but the app crashes as soon as it runs
Have you created your Parse application and inserted your specific codes from there to the demo ?
 
Top