![](/img/trans.png)
[英]How to pass ArrayList<File> object from one Activity to another Activity using Intent?
[英]How to pass object from one activity to another activity without using Intent
我是開發Android的新手。我有一個問題。 如何在不使用Intent的情況下將對象從一個活動傳遞到另一個活動。我可以通過Interface進行操作嗎,如果可以,請問我該如何處理
我想你有兩個選擇
將數據保存在單例類模型中,並從另一個活動中獲取相同的對象創建這樣的類
public class SingletonModel {
private static SingletonModel instance;
public String textData = ""
public synchronized static SingletonModel getSingletonModel() {
if (instance == null) {
instance = new SingletonModel();
}
return instance;
}
private void SingletonModel(){}
}
從第一次活動開始就這樣
SingletonModel.getSingletonModel().textData ="Your data goes here";
從第二個活動開始,像這樣
textView.setText(SingletonModel.getSingletonModel().textData);
如果數據應該保留,請使用文件。 如果不是,請使用單例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.