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,067
Last edited by a moderator:

Gentry

Member
Licensed User
Longtime User
Getting this error trying to compile using the Simple Library Compiler. Any ideas on where I should look? I'm trying to rename the library to Parse2, but did not see any references inside the wrapper java to specify self package name. also, I added all of the base v5.2 libraries to the libs directory to solve the dependancy errors I had initially.

B4X:
Starting step: Compiling Java code.
javac 1.7.0_75
C:\Users\gentry\Desktop\SimpleLibraryCompiler\Parse2\src\anywheresoftware\b4a\objects\ParseObjectWrapper.java:602: error: <anonymous anywheresoftware.b4a.objects.ParseObjectWrapper$ParseQueryWrapper$2> is not abstract and does not override abstract method done(List,ParseException) in FindCallback
            {
            ^
Note: C:\Users\gentry\Desktop\SimpleLibraryCompiler\Parse2\src\anywheresoftware\b4a\objects\ParseObjectWrapper.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error


Error.

More details - After commenting out Find, to bypass the above error, Now I hit a more troubling one:

B4X:
Starting step: Compiling Java code.
javac 1.7.0_75
C:\Users\gentry\Desktop\SimpleLibraryCompiler\Parse2\src\anywheresoftware\b4a\objects\ParseObjectWrapper.java:1168: error: method initialize in class Parse cannot be applied to given types;
            Parse.initialize(this, appID, clientKey, serverURI);
                 ^
  required: Context,String,String
  found: ParseApplication,String,String,String
  reason: actual and formal argument lists differ in length

My guess it the ParseNative.jar is where this is defined. Is that library a B4A library, or did that come from Parse directly?

Any clues are appreciated
 
Last edited:

adrianstanescu85

Active Member
Licensed User
Longtime User
Hello everyone!

I was wondering if anyone with a Parse app ran through the B4A library here (which I do find very very useful!) migrated their app to Heroku or any other solution, given the fact that Parse will close in about 9 months.

I have an app that's very dependent on the Parse database and it would be insane just to refigure out everything.

Any ideas?

Thank you!
Adrian
 

jamesnz

Active Member
Licensed User
Longtime User
I've been looking at dreamfactory but haven't started migrating yet.
I'd be keen to see a library for that
 

adrianstanescu85

Active Member
Licensed User
Longtime User
Since the Parse functionality would be preserved and the apps migrated, I was wondering if the current library can be modified accordingly.
 

Serdar K.

Member
Licensed User
Longtime User
It would be very nice to have some libraries for alternatives (Azure, Google Cloud service, AWS, etc.) or the Parse library updated supporting the last native SDK.
My experience is not enough yet, unfortunately.

I would like to ask a question :

When updating a ParseObject of a class on cloud, we can find a record, update other fields and
add items to an array field(object) like :

B4X:
...
po02.Add("QuestionIDs", Questions.vQuestionData(vIX001-1).QuestionID )
...

and then save the updated record :

B4X:
...
po02.Save("po02", 1)
...

But I can't replace the array fields(objects). They continuously grow up having new data added and old data kept.

Would something like :
B4X:
...
Dim po1 As ParseObject
po02.Put("QuestionIDs", po1 )
For vIX001 = 1 To Questions.vQuestionCnt
po02.Add("QuestionIDs", Questions.vQuestionData(vIX001-1).QuestionID )
  Next
...

work for replacing all items of "QuestionIDs" ?

I couldn't find anything relating removing a field's data when it is an array.
When i run a put method, it works on other fields, but when in array fields,
for example, for removing existing 30 items and adding new 30 items, i couldn't access
a solution.

Thanks & regards,
Serdar
 

Serdar K.

Member
Licensed User
Longtime User
I couldn't find any solution and moved into a string field containing a JSON String.
So, since there is no array, there is no problem.

It would be very nice to have some libraries for alternatives (Azure, Google Cloud service, AWS, etc.) or the Parse library updated supporting the last native SDK.
My experience is not enough yet, unfortunately.

I would like to ask a question :

When updating a ParseObject of a class on cloud, we can find a record, update other fields and
add items to an array field(object) like :

B4X:
...
po02.Add("QuestionIDs", Questions.vQuestionData(vIX001-1).QuestionID )
...

and then save the updated record :

B4X:
...
po02.Save("po02", 1)
...

But I can't replace the array fields(objects). They continuously grow up having new data added and old data kept.

Would something like :
B4X:
...
Dim po1 As ParseObject
po02.Put("QuestionIDs", po1 )
For vIX001 = 1 To Questions.vQuestionCnt
po02.Add("QuestionIDs", Questions.vQuestionData(vIX001-1).QuestionID )
  Next
...

work for replacing all items of "QuestionIDs" ?

I couldn't find anything relating removing a field's data when it is an array.
When i run a put method, it works on other fields, but when in array fields,
for example, for removing existing 30 items and adding new 30 items, i couldn't access
a solution.

Thanks & regards,
Serdar
 

Serdar K.

Member
Licensed User
Longtime User
After a long examination, i set up a server on Amazon Web Services.
It is effective regarding the price, and it seems not being shut down in a near future.
By the way, actually Parse used this service for storing and serving our data.

You can start with setting up an account with the free tier.
If you can find Bitnami Parse Server in marketplace (The free one), you can set your
server on a t2.micro instance for free in 5 minutes.

The story begins here.
The server is working fine but you should even enable the HTTP authentication for Dashboard.
Or anyone knowing the URL can access the dashboard and make changes.
There are some key points to find in Bitnami and Parse documentation.
Then you should enable SSL. If you have your own keys, it is also possible to install this ones.

I didn't still migrate my data and i'm going on testing.

Except Parse, I have also Firebase in mind because of the Realtime DB functionality, but the long term pricing
and native library issues are some concerns for me.

Regards,
Serdar

Hello everyone!

I was wondering if anyone with a Parse app ran through the B4A library here (which I do find very very useful!) migrated their app to Heroku or any other solution, given the fact that Parse will close in about 9 months.

I have an app that's very dependent on the Parse database and it would be insane just to refigure out everything.

Any ideas?

Thank you!
Adrian
 
Top