android - showDialog button doesent calls method i told him to -
ok got activity doesent have layout, there take gps coordinates , if succeed default camera intent started, if not show him dialog user have 2 buttons 1 cancel , go starting activity , second 1 try getting picture again (calling method obtaining gps , sending camera intent).
the problem when hit try again button doesent call getpicture() methond continue on button never hit nor dialog shown , problem happens
here code:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getpicture(); } public void getpicture(){ locationmanager locationmanager = null; locationmanager = (locationmanager)getsystemservice(context.location_service); locationlistener = new mylocationlistener(); locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, locationlistener); if(locationmanager.isproviderenabled(locationmanager.gps_provider)){ if(mylocationlistener.latitude>0){ intent cameraintent = new intent(android.provider.mediastore.action_image_capture); startactivityforresult(cameraintent, camera_request); } else { showdialog(gps_cant_connect); } }else{ showdialog(gps_off); } } @override protected dialog oncreatedialog(int id) { dialog d = null; switch (id){ case gps_off: { alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("please turn on gps before taking picture"); builder.setneutralbutton("try again", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { getpicture(); } }); builder.setnegativebutton("cancel", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { intent intent = new intent(startcameraactivity.this, mainactivity.class); intent.setflags(intent.flag_activity_clear_top); startactivity(intent); } }); d = builder.create(); break; } case gps_cant_connect: { alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("gps cant coordinates! please make sure outside"); builder.setneutralbutton("try again", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { getpicture(); } }); builder.setnegativebutton("cancel", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { intent intent = new intent(startcameraactivity.this, mainactivity.class); intent.setflags(intent.flag_activity_clear_top); startactivity(intent); } }); d = builder.create(); break; } return d; }
just add:
d.show();
after every d = builder.create();
line.
because have create dialog not show thats why not showing.
like:
case gps_cant_connect: { alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("gps cant coordinates! please make sure outside"); builder.setneutralbutton("try again", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { getpicture(); } }); builder.setnegativebutton("cancel", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { intent intent = new intent(startcameraactivity.this, mainactivity.class); intent.setflags(intent.flag_activity_clear_top); startactivity(intent); } }); d = builder.create(); d.show(); break; }
Comments
Post a Comment