Particle Cloud communication issues

I am working on an Android app that can send events to a Photon and vice versa. I have a system set up that allows for the following exchange of information:

• App sends message “register” to board
• Board receives event and sends its own event to the app
• App parses data and displays it to the user

This exchange works perfectly except for one flaw - after the app sends “register” once, the board stops publishing its events. I have checked the Particle logs and the serial monitor - the event is being sent from the app and the Photon’s handler function for the subscription is running, yet it does not publish its event.

Here is the handler function:

void myHandler(const char *event, const char *data)
{
  String e = event;
  String d = data;
  
  Serial.println(e);
  Serial.println(d);
  
  String total = "REGISTER:name=Test;LED On,LED Off";
  Particle.publish("mainBoard", total);
  runTask(data);
}

Here is the function sending the events in the app:

private class registerTasks extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            try {
                ParticleCloudSDK.getCloud().publishEvent("register", "", ParticleEventVisibility.PRIVATE, 60);
            } catch (ParticleCloudException e) {
                e.printStackTrace();
            }

            return "wibbly wobbly timey wimey";
        }

        @Override
        protected void onPostExecute(String result) {
        }
    }

Is this a problem with the app, the Photon or Particle Cloud?

The interesting thing in that connection might be what happens in runTask() and what happens after the handler finishes?
The actual Particle.subscribe() instruction and its location in your code would be interesting too.

Also Particle.publish() does only enqueue the event to publish but doesn’t wait for it to get delivered.

You could also check the return value of the publish call whether if does succeede at all.

Here is runTask():

void runTask(String data) {
    if (data[data.length() - 1] != ';') {
        tasksTimed[tasksTimedCount] = data;
        tasksTimedCount++;
        tasksTimedList += data + ',';
        
    }
    
    if (data == "LED On;") {
        digitalWrite(D7, HIGH);
    }
    
    if (data == "LED Off;") {
        digitalWrite(D7, LOW);
    }
}

Particle.subscribe() is in the setup() function on the Photon.

Here is the subscription function in the app:

private class Subscribe extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            long subscriptionId;
            try {
                subscriptionId = ParticleCloudSDK.getCloud().subscribeToAllEvents(
                        "mainBoard",  // the first argument, "eventNamePrefix", is optional
                        new ParticleEventHandler() {
                            public void onEvent(String eventName, ParticleEvent event) {
                                //Toaster.s(MainActivity.this, event.dataPayload);

                                String info = event.dataPayload;
                                String data = info.substring(info.indexOf(':') + 1);
                                String name = data.substring(data.indexOf('=') + 1, data.indexOf(';'));
                                String tasks = data.substring(data.indexOf(';') + 1);

                                subscriptionEvent(info, data, name, tasks);
                            }

                            public void onEventError(Exception e) {
                                Log.e("some tag", "Event error: ", e);
                            }
                        });
            } catch (IOException e) {
                e.printStackTrace();
            }

            return null;
        }
    }

And here is subscriptionEvent():

public void subscriptionEvent(String info, String data, String name, String tasks) {
        int boardId = boards.size() - 1;

        boards.add(boardId + "-" + name);
        String[] taskArray = tasks.split(",");

        for (int i = 0; i < taskArray.length; i++) {
            newTasks.add(boardId + "-" + taskArray[i]);
        }
    }