Android开发经验谈Android开发Android技术知识

记录Intent.createChooser导致意图选择弹窗消失

2020-02-14  本文已影响0人  blingbling_5a3f

1:使用Intent.createChooser的情况

代码

public void clickBtn(View view) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/*");
        startActivity(Intent.createChooser(intent,"分享"));
    }

效果

Demo.gif

应用选择弹窗会由于点击Home键或者最近任务键而消失。

2:不使用Intent.createChooser,直接startActivity(intent)

代码

public void clickBtn(View view) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/*");
        startActivity(intent);
    }

效果

Demo.gif

应用选择弹窗不会由于点击Home键或者最近任务键而消失。

上一篇 下一篇

猜你喜欢

热点阅读