Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Activity for result from IME

I'm developing an app that should return some text to the app that started the intent.

But the app that starts the intent is a IME/soft Keyboard. So StartActivityForResult is not available because an IME is a service.

How can I achieve this?

What I got so far:

Keyboard:

final Intent intent = new Intent("com.example.helloworld.GETTEXT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.putExtra("keyboard", true);
startActivity(intent);

Other App:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Bundle extras = getIntent().getExtras();
    if (extras == null){                
        return;
    } else {
        finish();
    }
}

@Override
public void finish() {
    Intent data = new Intent();
    data.putExtra("test", "PASSED");
    setResult(RESULT_OK, data);
    super.finish();
}
like image 787
Matthew Smissaert Avatar asked Nov 13 '22 16:11

Matthew Smissaert


1 Answers

You can use ResultReceiver. Look at this example, it's pretty clear explains how it works.

like image 145
Alex P. Avatar answered Nov 15 '22 04:11

Alex P.