【发布时间】:2021-10-20 18:58:23
【问题描述】:
我创建了一个中间类,里面保存了很多变量,例如:
public static class Middle{
public static List<Student> listStudent = new ArrayList<>();
public static String level = 1; (this example of level of a character in the game)
}
并为这些变量赋值
class A{
Middle.listStudent = GetData();
Middle.level++;
Intent intent = new Intent(A.this, B.class);
startActivity(intent)
}
然后在下一个类(或活动)中,我们将这些变量与新数据一起使用
class B{
ShowResult(Middle.listStudent);
ShowResult(Middle.level);
}
我使用这种方式是因为不想通过 Intent 传输数据。
我的问题是,我们是否可以在整个应用程序中过多地使用这种方式而不会出现任何问题,并且如果 中产阶级 由于任何原因关闭它会导致数据丢失?
【问题讨论】:
-
没有。使用单个对象将所有数据存储为全局静态数据将使您的程序非常难以维护和调试。这种技术一直流行到大约 50 年前。请不要自学以这种方式编程。
-
@DawoodibnKareem 为什么这会使程序难以维护和调试?
标签: java android android-activity