skip to Main Content

I am writting an Android application which gets data from URL in JSON format. I use fragments. Where I can do bussiness logic? On fragment ViewModel? The main idea, is get data from JSON URL link, analyze, get current device location, and display analyzed data on fragment. I am quite new in Android programming. Please advice or what is good practice to do it? Should I use android data repository?

Now I have fragment, viewmodel for fragment where I analyze JSON data

2

Answers


  1. Usually Android applications follow MVVM design pattern or sometimes MVP pattern, in addition to those sometimes we add Use Case – Repository – Service a typical app using latest technology and built from the ground up in a decent pattern and ready for unit testing would be like this.
    Model – View – ViewModel – UseCase – Repository – Service with each one having it’s own unique functionality, and all with a Dependency Injection running as well for testing, something like Dagger or Hilt for larger apps, or maybe Koin for smaller ones

    Login or Signup to reply.
  2. There are many architecture patterns and you can follow any one that suits your need. By default android follow mvc but most developers prefer mvvm since its also recommended by google itself.

    Since you are new to android I would suggest you to follow the default architecture (mvc) you can place the business logic in your activity or fragment (especially if your building a small app).

    First get familiar with android eco system by making different small apps then when you are confident move to advance topics. (Its my opinion, others can agree or disagree).

    Incase you prefer to follow other architecture patterns like mvvm then you can put your buisness logic in repository or use clean architecture with mvvm and place your business logic in usecases.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search