我剛剛發現導致了一段時間的錯誤。我有一個ArrayList,對於我想保存的每個對象,我想要一個用於AlarmManager的未決意圖列表,這樣,如果要從每個對象中刪除多個警報,我所要做的就是訪問列表的PendingIntents,並簡單地在整理列表中使用alarmmanagername.cancel(PendingIntent)。但是這些對象需要存儲,並且在檢索存儲對象時,arraylist被設置爲null,因爲我必須將其設置爲transient,以便將對象數據存儲並檢索到系統中而不拋出NotSerializableException。下面是類的設置方式:如何使用Android保存對象的不可序列化屬性?
public class ListObject implements Serializable{
public String objectname, startampm, stopampm; //name of schedule and am or pm
private boolean[] Days = {
false, //monday
false, //tuesday
false, //and soforth
false,
false,
false,
false};
private int starthour, startminute, stophour, stopminute; //times from TimePicker
public transient ArrayList<PendingIntent> pendintentlist = new ArrayList<PendingIntent>();; //ids for each of the alarms
private int listalarmid; //FOR WHEN COME BACK: maybe store pending intents instead of the array of ints above?
private boolean vibrate, activated;
private boolean nextday = false; //bool for if schedule goes into next day
據我瞭解,瞬時使得它到它不能與其他數據然而得救,我怎麼能去拯救這個非序列化對象與其餘的數據,所以當它被檢索到時,我可以訪問這個數組列表而不會變爲null?
如果沒有,是否有更簡單的方法可以稍後取消我想要保存的報警管理器?這是一個簡單的應用程序,可以讓你保存多個警報,我只需要一種方法來保存它們的未決意圖。