What is the standard way to organize Android code

2019-03-09 10:43发布

问题:

I'm new in android, I want to know what is the right way to write a code in an android project or which architecture or model should we use in our project example n-tire, MVC or other?

回答1:

check out this thread: Tips on organizing larger Android projects?

and this one: MVC pattern on Android

and this one: Which design patterns are used on Android?

and this one too: Android MVVM Design Pattern Examples



回答2:

Organize it in whatever way makes the most sense to you. There's no 100% correct way to organize an Android project... it depends on a number of factors (i.e. the size of your project).

If you want to see how Google organizes their projects, take a look at the Google I/O 2012 source code. In particular, check out the iosched.util package... it gives a number of ways to reuse code across your project (mostly by using static utility helper methods).



回答3:

This is actually a debatable question, but I will give my two pennies.

Considering Android is a portable system you need to consider that your application will not have unlimited power, and the power it does have has to be shared with other applications running on the system, by power I mean battery life, considering a large number of Android devices are actually quite healthy in terms of CPU and RAM, however even though most devices have more RAM these days, this RAM is still shared with other applications, so it should be used sparingly.

That said, any elaborate, highly engineered solution that prefers layering and abstraction over simply 'getting the job done' will probably suffer in the long run, the bottom line is the less instructions your application executes and the less memory your application uses, the more efficient it will be.

To give a more practical answer to your question, I would first make sure you are comfortable with core Android components such as content providers, services, broadcast receivers, intents and handlers, etc and work out from there.

Sorry for not giving a more specific answer, but I hope that helps a little.