java - Calendar Activity implementation. How to reload calendar view? Android -
i developing android app has calendar 1 of activities. calendar works fine have following problem:
for every month have make request events api (i using asynchttpclient achieve this), every time user clicks button see next or previous month, make new request, data asynchronously , save database. i'm doing right know starting new intent every new request, wrong because every time click see different month, if click button have bunch of instances of same activity previous months saw.
what want "refresh" calendaractivity new data got request, i'm not sure how this. tried adding flag flag_activity_new_task flags on intent doesn't expect. try put progressdialog , wait until request done problem still statactivity after request made, don't know how else can this.
here of code, particularly 1 have after request done , successful:
asynchttpclientmanager.java
public static void getcalendar(final int year, final int month, final context context, final context appcontext, final progressdialog prgdialog) { prgdialog.show(); cookiestore = new persistentcookiestore(appcontext); // change default timeout 10secs 30secs // calendar takes time load client.settimeout(default_timeout); client.setcookiestore(cookiestore); client.addheader("accept", header); requestparams params = new requestparams(); string[] dates = getdate(year, month); log.d(tag, "start: " + dates[0] + " end: " + dates[1]); params.put("start_date", dates[0]); params.put("end_date", dates[1]); client.get(getabsoluteurl(calendar_path), params, new jsonhttpresponsehandler() { @override public void onfailure(int statuscode, org.apache.http.header[] headers, java.lang.string responsestring, java.lang.throwable throwable) { prgdialog.hide(); ..... } @override public void onsuccess(int statuscode, header[] headers, jsonobject response) { if (statuscode == 200) { prgdialog.hide(); gson gson = new gson(); calendar calendar = gson.fromjson( response.tostring(), calendar.class); calendarcontroller.getinstance(context); calendarcontroller.insertcalendar(calendar); intent intentc = new intent(context, calendaractivity.class); java.util.calendar current = java.util.calendar .getinstance(); if (current.get(java.util.calendar.month) + 1 == month && current.get(java.util.calendar.year) == year) { intentc.putextra("first_time", true); } else { intentc.putextra("first_time", false); intentc.putextra("month", month); intentc.putextra("year", year); } context.startactivity(intentc); } } }); } here onclick() method when clicking button see next or previous month:
calendaractivity.java
@override public void onclick(view v) { if (v == prevmonth) { if (month <= 1) { month = 12; year--; } else { month--; } asynchttpclientmanager.getcalendar(year, month, this, getapplicationcontext(), prgdialog); setgridcelladaptertodate(month, year); } if (v == nextmonth) { if (month > 11) { month = 1; year++; } else { month++; } prgdialog.show(); asynchttpclientmanager.getcalendar(year, month, this, getapplicationcontext(), prgdialog); setgridcelladaptertodate(month, year); } } i tried finish calendaractivity before making request, request takes time current calendaractivity finishes, gets me previous activity , few seconds later new instance of calendaractivity gets launched.
hope can me this. in advance.
Comments
Post a Comment