How to send result from an implicit intent?

2019-09-11 21:02发布

问题:

I have read this thouroughly, but still can't find a solution, sharing doesn't work: Please pay attention particularly at the last part: http://developer.android.com/training/basics/intents/filters.html I am trying to implement little thing with implicit intents. So, app1 sends image to app2 on button click. App 2 recieves, displays the image and sends result ok to app 1. My problem is that whenever from OnCreate of app2 I call triggerNotification() my app stops working, more precisely, share button from app 1 results in the same page. In contrast, when I just comment triggerNotification() share button works fine.

Please see code snippet from app 2:

Some part of app2 onCreate:

if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("image/jpeg".equals(type)) {
                Uri imgUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                if (imgUri != null) {
                    //This also does not work.
                    ImageView imageView = (ImageView) findViewById(R.id.image);
                    imageView.setImageURI(imgUri);
                    triggerNotification();
                }
            }
        }
    }

The method that spoils everything:

public void triggerNotification() {
    Intent intent = new Intent();
    setResult(RESULT_OK, intent);
    finish();
}