Too many Activities in Android?

后端 未结 6 1961
春和景丽
春和景丽 2021-02-13 14:24

When i started my Android project i had a misunderstanding that every screen that\'s shown in the application must be a new activity. Now i am finished with the project , i have

6条回答
  •  不知归路
    2021-02-13 14:51

    The Android system tries to maintain an application process for as long as possible, but eventually needs to remove old processes to reclaim memory for new or more important processes. This applies to Activitys that are running in the background... old Activitys are managed for you and are destroyed when the system needs to reclaim memory for new processes.

    That being said, I think there are two things you should consider:

    1. User experience. Does your app really require 15-20 Activitys? Can you cut down the number of screens somehow? Less Activitys is usually better, since it requires less interaction when the user is navigating the application.

    2. Code design. While each Activity will have its own separate class, this does not restrict you from making smart design-decisions when implementing your application. For example, you might try grouping similar Activitys by having them extend an abstract class. As Android projects grow in size, they become more difficult to manage. Sharing code amongst similar classes in this manner will ensure that you can make simple changes to the core of your application without too much trouble.

提交回复
热议问题