I am writing a little calendar app for Android and I need some functions the Calendar
class contains (for example: calculate first day of month, current day of month, day of next month, year of a specific Unix timestamp and so on)
These functions are called frequently and they trigger GC_Concurrent pretty often which causes my app to lag.
This is the way I access the calendar functions:
private static Calendar cal;
public static int getDayOfMonth(long sec) {
if (cal == null)
cal = Calendar.getInstance(TimeZone.getDefault());
//cal.clear();
cal.setTimeInMillis(sec * 1000L);
return cal.get(Calendar.DAY_OF_MONTH);
}
Is there a better way to access the functions without producing so much garbage or a better way to calculate the things I need?