keyboard automatic pops up when moving from one activity to another

1k Views Asked by At

In my application when i go from one activity to another soft keyboard automatically pops up.

i have one activity(Say A) on which i have set

  android:configChanges="keyboardHidden" 

because i don't want keyboard on this activity but when i move from this activity to another activity(say B) which contains Map and AutoComompleteTextView, keyboard first automatically pops up and then close down.

what i have tried on activity B: In manifest i have set

android:windowSoftInputMode="stateHidden|adjustResize"

in oncreate

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

i also tried putting this in OnCreate

  try{
        View view = this.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }catch (Exception e)
    {
        Log.e(TAG, "onCreate: keyboard crash");
        e.printStackTrace();
    }

i also tried to set focus on another view in activity like(View v1)

 v1.requestFoucs();

i even tried putting

android:focusableInTouchMode="true"

on each and every component on activity B.

but nothing worked for me.

please help me to solve this problem i have already tried all the accepted ans that belongs to list of links below:

OnScreen keyboard opens automatically when Activity starts

Automatic popping up keyboard on start Activity

How to avoid automatically appear android keyboard when activity start

this is my AutoComompleteTextView

<AutoCompleteTextView
            android:id="@+id/auto_serviceArea"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:layout_weight=".5"
            android:background="@android:color/transparent"
            android:cursorVisible="false"
            android:hint="@string/serviceArea"
            android:padding="5dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:singleLine="true"/>

Edit 1: I tried to check that which view is getting focus so i can shift that focus, and while debugging i removed focus from AutoCompleteTextView but still keyboard appears and gone when activity starts. So this is not an Autocomplete focus problem.

4

There are 4 best solutions below

3
On BEST ANSWER

If you have tried everything that comes as an accepted ans according to your links for the ques, then why don't you try debugging your start activity, i mean on which you have put intent to start the respective activity. While debugging one of my application i found that android soft keyboard has that problem of not going down even after finishing the activity that calls it, it stays on screen for few seconds but this doesn't happen frequently.

So i suggest you to debug your calling activity too just try putting "focusable=false" on the component from which you called the respective activity.

0
On

Use these lines in java file:

InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
6
On

Simply what you need to do is to give

android:windowSoftInputMode="stateHidden"

in Manifest file of your Activity.

0
On

Write below line inside your main xml tag

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

just as below

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true" >