Siyateagan
Siyateagan

Reputation: 23

Move methods to a separate class

So, i have MainActivity. It has a large number of methods that relate to different aspects of the application. For example, I have 5 methods related to the implementation of the calendar (methods like getCalendarView(), setCalendarSettings(), etc.), which occupy a large place in the code. Should I put the calendar methods in a separate class, and in the MainActivitiy code just call these methods? Would it be considered good practice or leave it as it is?

Upvotes: 2

Views: 188

Answers (1)

MrVasilev
MrVasilev

Reputation: 1563

First, don't put any business logic inside your Activity. Your Activity is your View and has to handle the user interactions and update the UI based on the responses from your Data Source. In other words, you have to separate and group your code in layers which to communicate each other and every one of them has to has specific job.

Best practice in Android is to use some an architecture pattern like Clear Architecture, MVP or MVVM, I recommend MVVM.

You can start from here: https://developer.android.com/jetpack/docs/guide

and continue with this: https://medium.com/upday-devs/android-architecture-patterns-part-3-model-view-viewmodel-e7eeee76b73b

You also can check some examples here: https://github.com/android/architecture-samples

Upvotes: 1

Related Questions