簡體   English   中英

在兩個類之間進行序列化和反序列化

[英]serialize and deserialize between 2 classes

我正在嘗試在程序中實現以下結構:

    public abstract class A extends Service {

    public abstract void getData();

    //variables
    public int onStartCommand(Intent intent, int flags, int startId) {
    mHandler.postDelayed(1*1000, mHandler);
    return START_STICKY;
    }

    public Runnable runnable = new Runnable() {

    public void run() {

    AnotherClass ac = new AnotherClass();
    ac.method();

    // AnotherClass implements Serializable and stores all data.

    A start = new B();
//Start abstract method getData defined in class B
    start.getData();
    mHandler.postDelayed(runnable, 1 * 1000);
    }
    };
    }

現在B是擴展A的類。

public class B extends A {

public void getData() {

//Here I need to fetch the data from ac(AnotherClass) object which was serialized.

//perform my activity.

}
}

我是這個可序列化概念的新手。 我可以用它來實現上述結構嗎? 另外,我可以將ac對象的內容序列化為向量嗎? 請指導我,一個例子將非常有幫助。

這是為您提供序列化和反序列化的示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM