以旧方式开始新活动或更新值,哪种解决方案更适合性能?

时间:2017-04-25 07:40:12

标签: android xml performance class structure

Hello Stackoverflowers,

正如我的问题所说,对编程和性能更有效。

正在进行更新的“下一页”按钮();并更新活动中的每个文本视图。 (我目前的方法)

或startActivity(本身)的“下一页”按钮。本身是相同的布局,但新的“页面”具有相同的功能。

也许有人能够做出一个很好的例子,或者有一个链接来解释一个Android应用程序的攻击者。它有用,但我想让它变得专业。

按钮应该能够设置:

  • 文字到多个textviews
  • 如果您返回到最后一页(因为活动是可滚动的),则设置在linearLayout中选中的复选框
  • 安全选中复选框
  • 不要中断正在运行的计时器

我想要的每一个功能都已经存在..但它运行所有更新();我不确定这是否是处理资源的好方法

我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:fillViewport="true"
android:layout_height="fill_parent"
android:background="@color/Hp_background2"
android:weightSum="100"
>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="10"
        android:weightSum="100"
        >
        <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textAllCaps="false"
        android:layout_weight="33"
        android:textSize="10dp"
        android:id="@+id/pruefungBeendenButton"
        />
        <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Timer"
        android:gravity="center_horizontal"
        android:layout_weight="34"
        android:id="@+id/timerTextview"
        />
        <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Fortschritt/60"
        android:gravity="center_horizontal"
        android:layout_weight="33"
        android:id="@+id/fortschrittTextview"
        />
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="0dp"
        android:layout_weight="80">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:weightSum="100">

                 <TextView
                    android:id="@+id/frageTextview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="3dp"
                    android:text="Frage"
                    android:textSize="18dp" />
                <View
                    android:layout_width="match_parent"
                    android:layout_height="2dp"
                    android:background="@color/black" />

                <LinearLayout
                    android:orientation="vertical"
                    android:id="@+id/LinearLayout_subfragen"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="1dp">
                </LinearLayout>
            </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:id="@+id/LinearLayout_antworten"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="1dp"
                    android:layout_marginRight="1dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:dividerHeight="0dp">

                </LinearLayout>
        </LinearLayout>
</ScrollView>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="10"
    android:weightSum="100">

    <Button
        android:id="@+id/vorherigeFrage_Button"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="20" />

    <Button
        android:id="@+id/beantworten_button"
        android:textAllCaps="false"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="60" />

    <Button
        android:id="@+id/naechsteFrage_button"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="20" />
</LinearLayout>
</LinearLayout>

你知道,我在一个程序Highscool,但它现在2年后,似乎我找不到一个良好的结构在android中的收件人。

MfG Phil

1 个答案:

答案 0 :(得分:0)

使用相同的活动将减少活动创建开销。因为创建多个活动将使它们保持在后台堆栈中,除非您使用所需的启动模式定义它们,例如单个任务,单个顶部将重新从后堆栈引入活动并将重绘它们