简体   繁体   English

android / java:在活动之间传递嵌套类

[英]android/java: passing nested classes between activities

I'm not sure of the best way to pass the outer class between activities. 我不确定在活动之间传递外部类的最佳方法。 Should I make them both parcelable? 我应该让它们都包裹吗? Just not sure how to do the parcelable array in the writeToParcel method. 只是不确定如何在writeToParcel方法中执行可拆分数组。

public class checklistItem  {

    String name;
    String date;
        ...
}

public class dailyChecklist  {

    ...
    checklistItem[] theList;
    ...
} 

You could extend the Application class in your app and create a reference there to the instanced object you want to share across activities. 您可以在应用程序中扩展Application类,并在其中创建要在活动之间共享的实例对象的引用。

Hope it helps. 希望能帮助到你。

A non-static nested class contains an hidden reference to its enclosing outerclass; 非静态嵌套类包含对其封闭的外部类的隐藏引用。 which can be useful sometimes but useless on other occasions. 有时可能有用,但在其他情况下却没有用。 If you don't need to call your outerclass from the inner class then you should declare your inner class as static. 如果不需要从内部类调用外部类,则应将内部类声明为静态。 This way, it will behave as an ordinary, non-nested class but its definition will still remains in the namespace of the outer class. 这样,它将像普通的非嵌套类一样工作,但其定义仍将保留在外部类的名称空间中。

Of course, for the purists, by class , I means here an instance (object) of that class. 当然,对于纯粹主义者,按class ,这里是指class一个实例(对象)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM