I have 2 activities, A and B. When A starts, it checks for a condition and if true, it calls startActivityForResult()
to start B. B only takes text input so it
I have got two way.
Method 1. Use the following code inside the OnCreate method
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
It will prevent popping up keyboard unless you click.
or
Method 2 You can move away the focus on other view like TextView by using "requestfocus" in the xml.
<TextView
android:id="@+id/year_birth_day"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="1991">
<requestFocus />
</TextView>
Method 3 ( I think it should be avoidable) Using the following code in the manifest-
android:windowSoftInputMode="stateVisible"
For me worked only this solutions: add in manifest for that activity:
android:windowSoftInputMode="stateVisible|adjustPan"
paste this after setContentView
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Try showing the keyboard with some delay. Something similar to this:
public void onResume() {
super.onResume();
TimerTask tt = new TimerTask() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourTextBox, InputMethodManager.SHOW_IMPLICIT);
}
};
final Timer timer = new Timer();
timer.schedule(tt, 200);
}