Android - Window leak error on ProgressDialog when device is in landscape -
i have looked @ many questions here , searched on internet couldn't find specific solution. main problem other questions refer is, window leak error
when go portrait landscape or vice versa. , answer mainly, because activity
destroyed , recreated, hence window leak error
.
but problem is, device in landscape, , app working fine, previous activities smoothly running, when try display progressdialog
, window leak error
thrown. exact same code works fine when in portrait orientation.
class downloadyearchartasynctask extends asynctask<string, integer, boolean> { private string username; private string city; private resources resources; private location locationofcity = null; private progressdialog progressdialog; public downloadyearchartasynctask(string username) { this.username = username; } @override protected void onpreexecute() { super.onpreexecute(); resources = getresources(); setrequestedorientation(activityinfo.screen_orientation_nosensor); progressdialog = new progressdialog(cityactivity.this); progressdialog.settitle(r.string.title_progress_dialog); progressdialog.setmessage(resources.getstring(r.string.first_message_progress_dialog)); progressdialog.setindeterminate(true); progressdialog.setcancelable(false); progressdialog.setprogressstyle(progressdialog.style_spinner); progressdialog.show(); } @override protected void onpostexecute(boolean result) { super.onpostexecute(result); progressdialog.dismiss(); boolean userupdated = false; if(locationofcity != null && city != null && !city.isempty()) { try { userdao userdao = new userdao(cityactivity.this); user user = userdao.readuser(); if(user == null) { if(username != null && !username.isempty()) { user = new user(0, username, city, locationofcity.getlatitude(), locationofcity.getlongitude()); userupdated = userdao.createuser(user); } } if(username == null) { user.setlocation(city); user.setlatitude(locationofcity.getlatitude()); user.setlongitude(locationofcity.getlongitude()); userupdated = userdao.updateuser(user); } } userdao.close(); } catch (exception e) { e.printstacktrace(); } } setrequestedorientation(activityinfo.screen_orientation_sensor); if(userupdated) { intent intent = new intent(cityactivity.this, todayactivity.class); intent.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task); startactivity(intent); overridependingtransition(r.anim.slide_in_from_right, r.anim.slide_out_to_left); } } @override protected void onprogressupdate(integer... values) { super.onprogressupdate(values); progressdialog.setprogress(values[0]); } @override protected boolean doinbackground(string... params) { boolean alldaysentered = false; try { city = params[0]; locationofcity = myjsonutil.getlocationofcity(params); list<day> yearchart = myjsonutil.getyearchart(locationofcity.getlatitude(), locationofcity.getlongitude()); if(yearchart != null && !yearchart.isempty()) { yearchartdao yearchartdao = new yearchartdao(cityactivity.this); alldaysentered = yearchartdao.createyearchartwithdays(yearchart); yearchartdao.close(); } } catch (exception e) { e.printstacktrace(); } return alldaysentered; } }
any suggestions or solutions appreciated.
the problem code, used setrequestedorientation(activityinfo.screen_orientation_nosensor);
because, according kevin gaudin's comment on this answer.
it looks if call
setrequestedorientation(activityinfo.screen_orientation_nosensor);
when device not in default orientation usage, activity orientation changed (destroyed , recreated) device default orientation. example, on phone, if hold in landscape orientation, activity switched portrait , landscape when reactivating sensors. same opposite issue archos a5 : using in portrait causes activity switched landscape , portrait.
here solution found, answered commonsware. solution little lengthy.
so people in rush, technique used solution not perfect.
1 - in manifest
, add android:configchanges="orientation|screensize"
activity in want show progressdialog
.
2 - in activity
, override onconfigurationchange(configuration newconfig)
:
@override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); }
Comments
Post a Comment