Android應用應該使用被以一種簡潔的文件結構組織,使你的代碼更容易閱讀。此外,合理的代碼以及類命名規則是非常重要的,以確保你的代碼整潔易于維護
Naming Convention
Java Code
Type | Example | Description |
---|---|---|
Variable | incomeTaxRate | All variables should be camel case |
Constant | DAYS_IN_WEEK | All contants should be all uppercase |
Method | convertToEuroDollars | All methods should be camel case |
Parameter | depositAmount | All parameter names should be camel case |
For Android Classes
Name | Convention | Inherits |
---|---|---|
Activity | CreateTodoItemActivity | AppCompatActivity,Activity |
List Adapter | TodoItemsAdapter | BaseAdapter,ArrayAdapter |
Database Helper | TodoItemsDbHelper | SQLiteOpenHelper |
Network Client | TodoItemsClient | N/A |
Fragment | TodoItemDetailFragment | Fragment |
Service | FetchTodoItemService | Service,IntentService |
Android Folder Structure
- com.example.myapp.activities - 包含所有的activities
- com.example.myapp.adapters - 包含所有基本的adapter
- com.example.myapp.models - 包含所有的數據模型
- com.example.myapp.network - 包含所有的網絡代碼
- com.example.myapp.fragments - 包含所有的fragment
- com.example.myapp.utils - 包含有的幫助代碼
- com.example.myapp.interfaces - 包含所有的接口