How to check registration

Greetings
Im writtinh to share something I had serious problems doing, wich is to check if the device is registered or not. I thinks this is the correc think to do, otherwise the registration will be executed each time the user open the app. Other way could be saving a boolen variable ins the sharedpreference memory, but this is not relaiable cause if the user delete the app data that boolean is going to be lost, and then the registration will happen again.
If any device is registered and the registration happens again, nothing wrong is returned -as fas as I know- but I think the correct operation is to check if the device is registered or not before making a choice.
So here is my code, first the registration is check and if is not then the registrations is called.

public class DeviceRegistrationOperations {
 public void getDeviceRegistration() {
 Log.d(GlobalApplication.APP_TAG_NAME, "chekcing registration");
 AsyncCallback asyncCallback = new AsyncCallback<com.backendless.DeviceRegistration>() {
 @Override
 public void handleResponse(com.backendless.DeviceRegistration response) {
 Log.d(GlobalApplication.APP_TAG_NAME, "registered =");
 }
 @Override
 public void handleFault(BackendlessFault fault) {
 Log.d(GlobalApplication.APP_TAG_NAME, "not registered =");
 registration();
 }
 };
 Backendless.Messaging.getRegistrations(asyncCallback);
 }
 private void registration() {
 Backendless.Messaging.registerDevice("XXXXXXX", new AsyncCallback<Void>() {
 @Override
 public void handleResponse(Void response) {
 Log.d(GlobalApplication.APP_TAG_NAME, "registration success");
 }
 @Override
 public void handleFault(BackendlessFault fault) {
 Log.d(GlobalApplication.APP_TAG_NAME, "registration fail = " + fault.getCode() + " " + fault.getMessage());
 }
 });
 }
}


Now you can call the class in any activity and check if there is registration, is there is not then the registration will be executed.
If for any reason Im making any mistake, please admins, I encourage you to correct me, and please improve your documentation, situations like this https://backendless.com/documentation/messaging/android/messaging_managing_registrations.htm are very common. Your documentation have to be fool proof, if any rookie developer like me see that is going to have a hard time trying to figure it out.
Hope to help.

Hi Erick,

Are you saying there is a problem with the code you posted? Is it not working as you’d expected?

Regards,
Mark

Hello Mark

No, not at all, is working. The problem is the documentation is not ment to be read by noob developers, so it took me a lot of time to figure it out how to do it. That is why I decided to post this, so if any other beginner like me get stuck, maybe I can spare them the pain.

Im trying to be helpfull to others in a similar situation, you know, contributing to the Backendless community.

PS: LOL, Im listening the webinar about push notifications now and you are the one talking.

Thanks for contributing! We definitely encourage our users to help each other.

As for the doc, the information about retrieving device registration is right there:
https://backendless.com/documentation/messaging/android/messaging_retrieve_device_registration.htm

In fact, in the description of the API it says:

To retrieve device registration or to check if the device is registered with Backendless, application can use the API described below:

I do not know how to make it even more obvious, especially since the chapter name is “Retrieve Device Registration”:
http://support.backendless.com/public/attachments/cf6968667177af0706c6dc6a78538796.jpg</img>

Regards,
Mark

Mark

I know where it is, I found it, I read it, and then I pass through a painfull process figuring out how to make it work. This is the problem:

If you copy paste this in to your app

public void getDeviceRegistration( AsyncCallback<DeviceRegistration> responder );

Nothing is going to happen. Even if you try to write it and hope for the IDE to hint you, nothing is going to happen. Im talking about copy/paste cause any beginner has no clue about what is doing, so how can we pretend a beginner developer to learn something if it doesnt work by copy/paste and the beginner neither have previous experience even less conceptual knowledge to solve the problem? We cant.

My recommendation is to provide usable code and several examples of it. Also explaining very detailed what is going to be done. If the developer can create a new class to do it, explicitily say it and show that way, if the developer can do it in the android Activity explicitily say it and show that way. If there are any params combination talk about all, and provide with code for the most importants if there are too many.

I think the best example of documentation is the Wordpress Codex, that documentation is so good, that any person without php background cand just create a project from scratch, you should aim to that https://codex.wordpress.org/

Im not an experienced developer, also I learn software programming by my own (I went to college but I major in sociology). So I’ll be glad to share everything I consider painfull, because when I was learning (Im still learning), I went through a lot of pain, I can relate with other beginners very closely, I really like to help (or at least try to).

Hugs Mark :slight_smile:

I understand, Erick. I am sorry about the frustration you had experienced. As a general rule, we put an example at the bottom of every doc chapter. There is actually one on that page too ))

String applicationID = "";String secretKey = "";String version = "";String gcmSenderID = "";Backendless.initApp( applicationId, secretKey, version);DeviceRegistration devReg = Backendless.Messaging.getDeviceRegistration();

I dont see the AsyncCallback in the example.

Mark

Can you please edit my first post? I used a real project number by mistake LOL

Allready shut it down, but just in case, please?

Thanks.

Done

Thanks Mark, owe you one :slight_smile: