2012-04-20 37 views
0

我putExtras的getSerializableExtra日曆中的活動答:我不能恢復使用意向

notificationIntent.putExtra(KEY_ID, id); 
notificationIntent.putExtra(KEY_CALENDAR, day); 
A.logCalendar("calendar: ", day); // the Calendar is not null at this point 

我getExtras EN活動B:

int id = intent.getIntExtra(Constantes.KEY_ID, 0); 
A.b("My id: " + id); // The id is recovery 
Calendar time = (Calendar) intent.getSerializableExtra(Constantes.KEY_CALENDAR); 
if (time == null) 
    A.b("null calendar"); // The calendar is always null, WHY? 

我在做什麼錯。提前致謝。

+1

你爲什麼要那樣做?只需在每個活動中創建一個日曆。 'Calendar'只是日期和時間計算的幫手。如果你想傳遞一個時間點,使用'java.util.Date'類或毫秒作爲'long'。 – Stephan 2012-04-20 15:16:42

+0

有時我們離樹很近,以至於看不到森林。謝謝。我會用很長的毫秒。 – Jesus 2012-04-20 19:17:31

回答

0

您無法序列化整個日曆對象並使用Extra來發送它。您只能發送基元,數組和字符串。您可能需要考慮Parcellable等替代方案。