android - Activity 太多会影响我的表现吗?

标签 android performance android-activity stack

所以,我有近 20 个 Activity ,因为我有近 20 个布局,其中包含重要信息(关于应用程序内容)。好吧,我不得不说在这些 Activity 中主要是 TextViews。

是否有类似“Stack”的东西可以放置 Activity?如果有堆栈,是否会影响运行应用程序时的性能?我怎样才能看到这个堆栈?

应用程序应该有多少 Activity 是否有规则,还是取决于应用程序的用途?

如果您能向我解释 Activity 是如何举行的,或者在我运行我的应用程序时如何处理这些 Activity ,那就太好了。因为我不希望这 20 个 Activity 影响我的表现。

最佳答案

第一个问题:

Is there something like a "Stack" where Activities can be put? If there is a stack, does it affect the perfomance when running the app? How can I see this stack?

是的,您可以将 Activity 安排在一个任务中,该任务将它们组织在一个返回堆栈中。请参阅有关如何使用它们的文档。

A task is a collection of activities that users interact with when performing a certain job. The activities are arranged in a stack—the back stack)—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages. When the user selects a message, a new activity opens to view that message. This new activity is added to the back stack. If the user presses the Back button, that new activity is finished and popped off the stack. The following video provides a good overview of how the back stack works.

来源:https://developer.android.com/guide/components/activities/tasks-and-back-stack.html

第二个问题:

Is there a rule of how much Activities an App should have or does it depend on what the purpose of the App is?

是的,您的应用需要的 Activite 数量取决于用例,甚至取决于您构建项目的风格。例如,您还可以使用 Fragments 并在需要时将它们替换为一个 Activity。两种方式各有利弊。

关于android - Activity 太多会影响我的表现吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44863484/

相关文章:

android - 在 Android Studio 0.4.0 中添加新首选项屏幕的选项在哪里?

android - html中的图像大或小

ios - 在 Objective-C 中使用带或不带后缀 .f 的 CGFloat 是否存在性能差异

java - getActivity() 在 Android java 服务中使用的其他方式

android - 在创建 ViewModelProvider 实例时将“this”和 "activity!!"作为 ViewModelStoreOwner 传递有什么区别

java - 在没有 Activity 的情况下调用 SharedPreferences、Intent 和 Retrofit

java - 以智能方式取消计算线程

java - 在java中什么会更有效率? If-return-else 还是 If-return?

android - 如果选中复选框,则启动另一个 Activity

android - 公开分享 SKU 安全吗?