android - How do I reference findFragmentByTag to re-display a softkeyboard? -


i have datepickerdialog launches in fragment. when orientation change occurs app crashes. logcat output says npe happens ondismiss in datepickerfragment. ondismiss code used toggle soft keyboard show again (after launch of datepickerdialog toggles off). inputmethodmanager launch soft keyboard uses "getactivity()" reference think causing crash after orientation since activity re-created. can replace reference fragment using findfragmentbytag way re-use dialogfragment upon orientation change?

here partial datepickerfragement file:

public class datepickerfragment extends dialogfragment implements datepickerdialog.ondatesetlistener {  public datepickerfragment() { }  @override public dialog oncreatedialog(bundle savedinstancestate) { ... datepickerdialog picker = new datepickerdialog(getactivity(),     this, year, month, day); return picker; }   public void ondismiss(final dialoginterface dialog) { inputmethodmanager imm = (inputmethodmanager) getactivity().getsystemservice(cardviewactivity.input_method_service); imm.togglesoftinput(inputmethodmanager.show_implicit, 0); super.ondismiss(dialog); }  }  activity file // uses show() launch dialogfragment:  public class activity extends appcompatactivity { ... datepickerfragment newfragment = new datepickerfragment(); newfragment.show(getsupportfragmentmanager(), "datepicker"); 

check if getactivity() not null in ondismiss()


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -