My app crashes whenever I try to do this:
for (CalendarEvent event : this.ListofEvents){
String myDate = new String(event.getDate());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
theDate = format.parse(myDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(theDate.getDate());
}
If I just print event.getDate() as a test, it displays all the dates. But when I try to format each date I’m assuming it locks up the phone resources. It’s a fairly large List with many entries.
Perhaps there’s a better method of getting the day, month, and year without taking up all the resources.
Why are you creating a DateFormat inside the loop? You create it, use it, and then it goes out of scope for GC in the next iteration.
Move it outside the loop: