Checking if a Topic Exists
You can check if a certain topic already exists from your mobile application.
The following example checks if the specified topic already exist in an application scope (you can similarly check the topic existence in a user and group scopes).
-
try { // Instantiate the target topic. KiiTopic topic = Kii.topic("SendingAlert"); // Check if the topic exists. boolean exists = topic.exists(); if (exists) { // The topic already exists. } else { // The topic does not exist. } } catch (IOException e) { // Handle the error. }
-
// Instantiate the target topic. KiiTopic topic = Kii.topic("SendingAlert"); // Check if the topic exists. topic.exists(new KiiCallback<Boolean>() { @Override public void onComplete(Boolean result, Exception e) { if (e != null) { // Handle the error. return; } if (result) { // The topic already exists. } else { // The topic does not exist. } } });
This is the brief explanation of the sample code:
- Get an instance of the topic that you want to check if it exists.
- Execute the
exists
method to check if the topic exists or not.