D
D
dendead2020-08-13 20:32:21
Java
dendead, 2020-08-13 20:32:21

How to properly store Events in classes?

I am using several packages in my android project.

For example:

com.app.example->activities
com.app.example->adapters

other.

I want to use classes with Events in different packages, but can I add them in one java file?
Due to scope, I can't do this:

public class Event1
{
            
}
        
class Event2
{
        
}


so:

public class Event1
{
        
}
        
public class Event2
{
        
}


I use the EventBus library (github.com/greenrobot/EventBus) for which I create a CustomEvent class for each event I use. For example: LogOutEvent event = new LogOutEvent(); EventBus.getDefault().post(event); If I have 50 events, I will have to create 50 classes. Tell me how to properly store classes with events in the project?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-08-15
@zagayevskiy

You don't need to store anything in the same events/activities/adapters package. It's stupid. Keep everything on features. Login package, inside LoginActivity, LoginAdapter, EventLogIn, EventLogOut, etc. Etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question