1

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.

Community
  • 1
  • 1
Rajat Porwal
  • 101
  • 8

4 Answers4

1

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.

Sunny
  • 58
  • 6
  • but i have put android:configChanges="keyboardHidden" in my calling activity , which means i have changed the keyboard accessibility on that activity so keyboard will never appear on that screen, Correct me if am wrong.? – Rajat Porwal Dec 20 '16 at 10:17
  • but OK i will try your suggestion because i don't have any other choice , I have tried everything on the current activity. – Rajat Porwal Dec 20 '16 at 10:19
  • i tried debugging the calling activity and as you suggested put focusable=false on the component from which i was calling new activity and it worked..!! That means problem is on calling activity, keyboard appears on calling activity. I dont know why this happens because i have already put android:configChanges="keyboardHidden" and android:windowSoftInputMode="adjustPan|stateUnchanged|stateAlwaysHidden" in menifest.xml still that keyboard appears on that activity. Can you Please Explain why this happens? – Rajat Porwal Dec 20 '16 at 12:12
0

Simply what you need to do is to give

android:windowSoftInputMode="stateHidden"

in Manifest file of your Activity.

Ashish Vora
  • 571
  • 1
  • 8
  • 27
0

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" >
Mahesh Babariya
  • 4,560
  • 6
  • 39
  • 54
0

Use these lines in java file:

InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
MashukKhan
  • 1,946
  • 1
  • 27
  • 46
RahulS
  • 11
  • 6