简体   繁体   中英

soft keyboard doesn't close and freeze when close

SCENARIO

My App is open 3rd party application from Activity C (A->B->C). After, 3rd party application finished it return to my application on Activity C. Everything work fine until only one EditText in Activity C was typing with soft keyboard and I want to close it.

Soft Keyboard freeze and not close, also my app didn't freeze.

  • My test device is base on Android KitKat.
  • I change to other keyboard both default and custom.. no hope
  • I push home button and return to my app again soft keyboard behavior fine.

Here is my Sample XML (which reproduce this bug)

ACTIVITY A

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Go to Activity B"
            android:id="@+id/btnNext"/>
</LinearLayout>

ACTIVITY B

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Go To Activity C"
            android:id="@+id/btnNext"/>
</LinearLayout>

ACTIVITY C

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbarStyle="outsideOverlay">



            <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/padding_medium"
                    android:background="#DEE1E3"
                    android:id="@+id/llReceiverContainer">


                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                    <EditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/padding_default"
                            android:hint="Receiver Name"
                            android:id="@+id/edtReceiver"/>
                </LinearLayout>

                <Button
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/button_height_big"
                        android:layout_marginBottom="@dimen/padding_default"
                        android:layout_marginLeft="@dimen/padding_default"
                        android:layout_marginRight="@dimen/padding_default"
                        android:text="Ex. Call 3rd Party App"
                        android:textColor="#fff"
                        android:textStyle="bold"
                        android:textSize="@dimen/font_large"
                        android:id="@+id/btnTestMpos"/>

            </LinearLayout>

</ScrollView>

Here is my Sample CLASS (A->B->C just call startActivity)

CLASS ActivityC

public class ActivityC extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_c);

        Button btnTestMpos = (Button) findViewById(R.id.btnTestMpos);
        EditText edtUser = (EditText) findViewById(R.id.edtReceiver);
        btnTestMpos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                payWithMPOS();
            }
        });
    }

    private void payWithMPOS() {
        //call thire pparty application
    }

    // return from 3rd party application
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        getResultFromMPOS();
    }

    public void getResultFromMPOS() {
        // extract result from 3rd party applicaiton
    }
}

MANIFEST

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.ui.keyboard"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="14"/>
    <uses-permission android:name="android.permission.GET_TASKS" >
    </uses-permission>


    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name=".ActivityA"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".ActivityB"
                  android:label="@string/app_name">
        </activity>
        <activity android:name=".ActivityC"
                  android:launchMode="singleTask"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="com.example.mpos.integration" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

try thisin your Activity C Java class

ScrollView yourScrollViewName= (Button) findViewById(R.id.yourScrollViewId);
yourScrollViewName.setOnTouchListener(this);

@Override
    public boolean onTouch(View v, MotionEvent event) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        return false;

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM