-2

Otto I use in the project. everything works but I want to improve. Now I have so I send messages from different places, such as

BusProvider.getInstance().post(new QueueMessage(s));
BusProvider.getInstance().post(queue);
BusProvider.getInstance().post(weatherResponse);

but all the methods I describe in MainActivity

@Subscribe
    public void showOttoQueue(Queue queue) {
        new NotificationStorege().setTicker("New message").setTitle("queue").setMessage("You are in the queue: "+queue.queue).generateNotification(this);
    }
    @Subscribe
    public void showGcmMessage(GcmMessage message) {
        Toast.makeText(this, "gcm message: " + message.Result, Toast.LENGTH_LONG).show();
    }
    @Subscribe
    public void showOttoRemoveQueue(QueueMessage message) {
        if (message.Result.equals("OK")){
            new NotificationStorege().setTicker("New message").setTitle("queue").setMessage("you are out of queue").generateNotification(this);
            Toast.makeText(this, "you are out of queue", Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(this, "error out of queue", Toast.LENGTH_LONG).show();
        }
    }

whether it is possible to create full of class that will store all of these methods? or should they only be in Activity which launched?

1 Answers1

0

You are free to use Otto in every single class you want. Just register instance of that class, like in code below. After that events will come to that object.

bus.register(classInstance);
Kaerdan
  • 1,180
  • 10
  • 9