java - Prevent android keyboard form causing lag -
i attempting use swipe gesture finish fragment, , if fragment displaying keyboard, keyboard hidden. following sample:
public void finishfragment() { view focus = getcurrentfocus(); inputmethodmanager imm = null; if (focus != null) { imm = (inputmethodmanager) focus.getcontext(). getsystemservice(context.input_method_service); if (imm.isactive()) { imm.hidesoftinputfromwindow(focus.getwindowtoken(), 0); } } if (getfragmentmanager().getbackstackentrycount() > 1) { getfragmentmanager().popbackstack(); } }
unfortunately, since calling service along side fragment stack, service hanging ui display, giving laggy appearance. know how can hide keyboard without calling service or should call async
process? better, know how onbackpressed()
removes keyboard?
there 2 ways control keyboard on android:
- programmatically inputmethodmanager doing (which far know requires call .getsystemservice() use)
- using android:windowsoftinputmode="x" specify behavior of keyboard in context of given activity tag in androidmanifest
so answer questions of: "does know how can hide keyboard without calling service"? following in androidmanifest, activityx activity want have type of behavior.
androidmanifest.xml:
<activity android:name="com.namespace.of.activityxyz" android:windowsoftinputmode="statehidden" />
this serve hide keyboard activityx, not sure if give desired behavior/lack of laggyness when swiping finish fragment. try changing "statehidden" "statealwayshidden" or "stateunchanged". checkout these here if not know.
another approach be: instead of checking focus , getting keyboard programmatically doing, why not finish() activity managing fragment wish end? hide keyboard if open.
hope helps!
Comments
Post a Comment