patrick
patrick

Reputation: 1292

Breakup a rather large android project into smaller components

I'm still quite new to developing android programs and getting in to trouble with my current project. It started of as a simple small project but it is getting way to big for one file.

I would like to split it up in several components for example ui, calculations and main. But what is the best way to do this.

Currently I've only got :

public class main extends Activity {...}

and

public class preference extends PreferenceActivity implements OnSharedPreferenceChangeListener {...}

Should I remove the functions from main an put it in for example:

public class ui extends main {...}

Upvotes: 3

Views: 481

Answers (2)

gnclmorais
gnclmorais

Reputation: 4971

I would follow a MVC/MVP/MVVM approach. I'm currently in a big Android project too, and I'm trying to divide my files by a model/view/ namespaces.

Upvotes: 0

Amokrane Chentir
Amokrane Chentir

Reputation: 30385

It is up to you to organize your project accordingly. My way of doing things is to have the following packages:

  • activities: Where I place all the activties.

  • types: Where I place all the types, like: User or Country.

  • exceptions: Where I place all my custom exceptions.

  • services.

  • providers: for the content providers.

  • preferences.

  • util: a package that holds all the classes that might be useful as a tool (like JSON parsers, String utility classes, Regular expressions etc.).

etc.

Inside the activities package you could add one class by activity. Calling one class ui is not a good idea, uicould be the name of the package (insead of activities). You should call your class in a way that it describes the functionality of your activity. For instance you can call it: LoginScreenActivity. I encourage you to check some open source projects like Shelves or Foursquare to study a possible way of organizing your android projects.

Upvotes: 2

Related Questions