My original plan was to use a shared class with static methods and variables but I read a lot of “don’t do that” threads so decided to go the Application route.
“不要那样做”通常是针对全局范围内的任何内容的建议,因此将涵盖静态数据成员以及自定义应用程序.两者都可能是内存泄漏的来源.
Now, I’ve run into a situation where I’m trying to use myAppClass in a Project Library but getting errors about android.app.Application cannot be cast to…
您在托管项目中的清单可能并未声明使用库的Application实现.
this is supposed to be a big no-no
同样,静态数据成员并不比自定义应用程序差,并且在许多情况下更好.
Is there another way to do this?
不要使用应用程序或静态数据成员.
Would I be better off to re-implement the entire application by passing huge (thousands of objects/members) ArrayLists back-and-forth between methods/classes?
拥有持久数据模型(例如数据库)会更好.使用静态数据成员作为持久数据模型的缓存是可以的,只要您对内存管理非常小心.