-2

I have created my own input method in android and in that i want to trigger this activity to count backspaces when it started running and send a value when the user closes the keyboard? is there a way to do this ?

ovina peiris
  • 1
  • 1
  • 4

1 Answers1

0

In the onKey() method of your IME keep a count of backspace key.

@Override
public void onKey(int primaryCode, int[] ints) {
    -----
    -----
    if (primaryCode == Keyboard.KEYCODE_DELETE){
        count++;
    }
    ----
    ----
}

Reset this counter in onStartInputView() method.

Now in onFinishInput() method, trigger the activity you want and put the number of backspaces as extras.

@Override
 public void onFinishInput(){
    Intent intent = new Intent(getApplicationContext(),MyActivity.class);
    intent.putExtra("backspace_count",count);
    startActivity(intent);
    super.onFinish();
}

I hope this is what you are trying to achieve.

Prasad Pawar
  • 1,606
  • 1
  • 15
  • 30