Problem with Message subscribe() sync API

Using Android SDK version : Backendless SDK v1.10 for Android, released 08.11.2014,

Using the following sync subscribe methods we don’t get an exception but we aren’t able to receive any Push Messages. The async methods all work with no problems.

Sync methods not receiving any messages:

Subscription subscribe( AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
Subscription subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
Subscription subscribe( int pollingInterval, AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
Subscription subscribe( String channelName, int pollingInterval, AsyncCallback<List<Message>> subscriptionResponder ) throws BackendlessException
Subscription subscribe( AsyncCallback<List<Message>> subscriptionResponder, SubscriptionOptions subscriptionOptions ) throws BackendlessException
Subscription subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder, SubscriptionOptions subscriptionOptions ) throws BackendlessException
Subscription subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder, SubscriptionOptions subscriptionOptions,int pollingInterval ) throws BackendlessException

Async methods working okay:

void subscribe( AsyncCallback<List<Message>> subscriptionResponder, AsyncCallback<Subscription> responder )
void subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder, AsyncCallback<Subscription> responder )
void subscribe( int pollingInterval, AsyncCallback<List<Message>> subscriptionResponder, AsyncCallback<Subscription> responder )
void subscribe( String channelName, int pollingInterval, AsyncCallback<List<Message>> subscriptionResponder, AsyncCallback<Subscription> responder )
void subscribe( AsyncCallback<List<Message>> subscriptionResponder, SubscriptionOptions subscriptionOptions, AsyncCallback<Subscription> responder )
void subscribe( String channelName, AsyncCallback<List<Message>> subscriptionResponder, SubscriptionOptions subscriptionOptions, AsyncCallback<Subscription> responder )
void subscribe( final String channelName, final AsyncCallback<List<Message>> subscriptionResponder, SubscriptionOptions subscriptionOptions, final int pollingInterval,final AsyncCallback<Subscription> responder )

We can not reproduce this problem. Try to use the latest version Android SDK -https://github.com/Backendless/Android-SDK

Ok, will do. Thanks Denis.

Denis,

My name is Niro and I work with Simon.

To reproduce the problem, please use attached file.

And about for the github’s code, we’ve met following problem.

(1) in “Backendless.initApp()” it caused following exception

Could not find class ‘java.beans.PropertyDescriptor’, referenced from method >>com.backendless.FootprintsManager$Inner.duplicateFootprintForObject

I think, It is because the FootprintsManage.java. It imports following packages, but in does not exists on the project.

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;

(2) The github’s source codes seems bit strange (or not newest one?). For example;

  • “Backendless.Messaging.cancel (Messaging.java:line 448)” 's parameter seems incorrect.

At current, It contains ;

public void cancel( String messageId, AsyncCallback<MessageStatus> responder )

But in your documents (http://backendless.com/documentation/messaging/android/messaging_cancel_scheduled_message.htm), it says

public void cancel( String messageId, AsyncCallback<Boolean> responder )
  • It does not contains following class.methods.
    GooglePlayPurchaseStatus.getPurchaseTime()
    GooglePlaySubscriptionStatus.getInitiationTimestamMsec()
    GooglePlaySubscriptionStatus.getValidUntilTimestampMsec()

Could you confirm?

#I’m sorry if my English was wrong and you don’t understand the meaning.

Regards,
Niro.

AutoTestActivity.zip (774B)

Hello Niro.
In the documentation there is an error. Proper method signature, such as in Android SDK:

public void cancel( String messageId, AsyncCallback<MessageStatus> responder )

We will fix the documentation soon.

Now your example:

  1. Android is prohibited attempts to perform a networking operation on its main thread.To do this, create a separate thread.
  2. You have incorrectly initialized application. Correct form - Backendless.initApp(AutoTestActivity.this, “F8506263-0D82-B70C-FFA5-2242980AB000”, “881A62C9-C411-C7EC-FFF5-8DBDBBAE0F00”, “v1”);
  3. About methods. On github always the latest code. The site has not yet had time to update the library. Today we will try to update. These methods have changed names.

I have attached an example with which you can test synchronous calls.

Regards, Denis

example.zip (1.64kB)

Thank you Dennis.

#English isn’t my first language, so please excuse any mistakes.

As you pointed out, it was thread related problem.
Actually, we cannot use the “strict mode” (we understand it can be use only for test purpose),
but we confirmed it works on testing environment.

And we found that the following code seems to work.

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);


    // In this case we beleve that Backendless.initApp(this,,,,) also 
    // work correctly because "this" instance is same as "MainActivity.this".
    Backendless.initApp(MainActivity.this,
		"<APPID>",
		"<APP SECRET>", "v1");


    // Creating normal thread caused follwoing exception.
    // "Can't create handler inside thread that has not called Looper.prepare()"
    // To avoid above, create HandlerThread.
    HandlerThread ht = new HandlerThread ("bethread");
    ht.start();
    Handler betestThreadHandler = new Handler(ht.getLooper());
    betestThreadHandler.post( new Runnable(){
    public void run(){
        subscription = Backendless.Messaging.subscribe( TEST_CHANNEL, new AsyncCallback<List<Message>>()
        {
          @Override
          public void handleResponse( List<Message> response )
          {
            for( Message message : response )
            {
              Object data = message.getData();
              Log.d( TAG, "SUCESS:message.data[" + data + "]" );
              ht.quit(); // need?
            }
          }
	          @Override
          public void handleFault( BackendlessFault fault )
          {
            Log.e( TAG, "FAIL:"+fault.toString() );
             ht.quit(); // need?
          }
        } );
       messageStatus = Backendless.Messaging.publish( TEST_CHANNEL, "Hello World!" );
    }
 }

It seems working fine but if you realize problem, please let me know.

Regards,
Niro.