![](/img/trans.png)
[英]Android - Passing intent with object from one activity to another (crashing)
[英]Passing android.text.format.Time object via Intent from one activity to another
有什么方法可以通過Intent
傳遞Time
類的對象嗎? 我已經搜索了通過Intent
傳遞的對象,但是它們不能解決我的問題,因為Time
類不繼承Parcelable
類或實現Serializable
接口。
您可以使用Singleton
傳遞對象。 我通常使用這種方法,因為解析對象太復雜了,無法實現如此簡單的目標。
public class Session {
public static final Session sharedSession = new Session();
public Time passedTime;
private Session() {
}
}
然后,您可以在任何Activity
或Fragment
訪問此passedTime
,如下所示:
Time time = Session.sharedSession.passedTime;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.