Hello,

for one of my apps i need to create a list of months for which data is
available. I do this by polling the first date for which data is
available and then use a loop to increment the date until i reach the
present.

The code looks roughly like this:

        Date startDate = new Date(firstAvailableDate);
                if(DebugFlags.LOG_HELPERS)
                        Log.v("Creating MonthObjects - Startdate - " +
startDate.toGMTString());
        GregorianCalendar today = new GregorianCalendar();
        GregorianCalendar xCal = new GregorianCalendar();
        xCal.setTime(startDate);
        xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay);
        while(xCal.before(today))
        {
// Create new Object to save Data in
                MonthObject xObj = new MonthObject();
                xObj.setTimestamp(xCal.getTimeInMillis());
                xObj.setFromDate(xCal.getTime());
// Add 1 Month to xCal
                xCal.add(GregorianCalendar.MONTH, 1);
// Set Day to Day on which Statistics should reset
                xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay);
// Make sure it's Midnight
                xCal.set(Calendar.HOUR_OF_DAY, 0);
                xCal.set(Calendar.MINUTE, 0);
                xCal.set(Calendar.SECOND, 0);
                xCal.set(Calendar.MILLISECOND, 0);
// Save it in Object
                xObj.setToDate(xCal.getTime());
                xObj.setToTimestamp(xCal.getTimeInMillis());

                if(DebugFlags.LOG_HELPERS)
                        Log.v("Added MonthObject - " + 
xObj.fromDate.toGMTString() + "
to " + xObj.toDate.toGMTString());
// Add to Collection
                dates.add(xObj);
                xObj = null;
        }
        xCal = null;
        today = null;
        return dates;

This works fine in 99% of cases; however, on at least one HTC Desire
with Android 2.1 this leads to an infinite loop and the log looks like
this:

D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to
30 Aug 2010 22:00:00 GMT

This is repeated until the app crashes. Also, GregorianCalendar seems
to ignore all attempts to change the date when used in another context
(also only on this one mobile).

Does anyone have a clue why this happens or what I'm doing wrong?

Thank you!

Andreas

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to