获取" getTextBeforeCursor on inactive InputConnection"警告信息

时间:2014-04-22 16:53:13

标签: android

以下是我实施的DeviceAdminReceiver子类的代码片段: -

public void onDisabled(Context context, Intent intent) 
{
    super.onDisabled(context, intent);

    AntiTheftApplicationContext.setApplicationContext(
        context.getApplicationContext());

    final Context applicationContext =  AntiTheftApplicationContext.
        getApplicationContext();

    Thread thread = new Thread(new Runnable() 
    {
        @Override
        public void run() 
        {
            applicationContext.stopService(new Intent(applicationContext,    AuthenticationWakeupCallReceiver.class));

            applicationContext.startService(new Intent(applicationContext, AuthenticationWakeupCallReceiver.class));

        }
    });

    thread.start();

    while(AntiTheftUtil.isMyServiceRunning(
           AuthenticationWakeupCallReceiver.class.getName()))
    {
        try 
        {
            Thread.sleep(20000);
        } 
        catch (InterruptedException e) 
        {
            e.printStackTrace();
        }
     }
}

AuthenticationWakeupCallReceiver启动另一个活动,即PostStartupAuthenticationActivity: -

if(!PostStartupAuthenticationActivity.isActivityRunning())
{
    Intent intent = new Intent(context,XYZ.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    context.startActivity(intent);
}

XYZ活动包含一个EditText,在布局文件中定义如下: -

<EditText
    android:id="@+id/re_enter_authentication_code"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="enter authentication code"
    android:inputType="textPassword"
    android:maxLines="1"
    android:singleLine="true" />

EditText的处理在我的代码中完成如下: -

final EditText dataEnteredEditText = (EditText)findViewById(R.id.re_enter_authentication_code);

TextWatcher watcher = new TextWatcher() 
{
    int countAttempts = 0;

    @Override
    public void onTextChanged(CharSequence enteredText, int start, int before, int count) 
    {
        String value = enteredText.toString();

        if(value.length() >= authenticationCode.length() &&       !value.equals(authenticationCode))
        {
            dataEnteredEditText.setError("Invalid Code!!!");

            dataEnteredEditText.setText(AntiTheftConstants.EMPTY_STRING);

            countAttempts++;

            if(countAttempts == 3)
            {
                SharedPreferences.Editor editor = sharedPref.edit();

                editor.putBoolean(AntiTheftConstants.USER_AUTHENTICATION_STATUS, false);

                editor.commit();            

                startProcessForAuthenticationFailure();

                finish();
//          }
        }
        else if(value.equals(authenticationCode))
        {
            mIsCorrectPasswordEntered = true;

            stopService(new Intent(AntiTheftApplicationContext.getApplicationContext(), AuthenticationWakeupCallReceiver.class));

            stopService(new Intent(AntiTheftApplicationContext.getApplicationContext(), AuthenticationWakeupCallReceiver.class));

            notifySuccessfulAuthentication();
       }
    }
}

问题1: - 但是,当从AuthenticationWakeupCallReceiver调用XYZ时,XYZ活动中定义的EditText将停止接受数字。当我输入简单的字母时,它被接受,但当我输入数字时,它不会被接受。我收到以下警告消息: - “getTextBeforeCursor on inactive InputConnection”。

问题2: - 我正在寻找一种更好的方法我想从DeviceAdminReceiver子类调用一个活动而不启动另一个线程来检查我的服务的运行状态。我可以在不启动单独线程的情况下开始我的活动。我只是想阻止控制流程,直到用户被验证。 DeviceAdminReceiver子类中的onDisabled方法只应在用户正确验证后才能完成执行。

0 个答案:

没有答案