android - 为什么 sharesheet 意图使我的 android 应用程序崩溃?
问题描述
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read_class);
btn = (Button) findViewById(R.id.button2);
imview = findViewById(R.id.imageView);
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
final File imageFile = new File(path, "enc" + ".png");
Bitmap bmp = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
imview.setImageBitmap(bmp);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri urii = Uri.fromFile(imageFile);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, urii);
startActivity(Intent.createChooser(intent , "Share"));
}
});
上面的代码在我的模拟器上运行良好,实际上速度正常。但是,当我安装 apk 时,此活动会使屏幕空白几秒钟。恢复后,图像视图工作正常,但当我单击按钮时,应用程序崩溃。我不知道如何调试它。
注意:这是在数据写入后加载的布局。但我怀疑数据是否写入缓慢。所以我在按钮功能中包含了文件读取语句。但是应用程序仍然崩溃。
解决方案
在图像完全加载之前使用coroutine
或放置progressbar
推荐阅读
- javascript - 如何在不创建 Promise 的情况下将 await 与异步函数一起使用?
- python - DJango admin base_site 模板扩展不起作用
- jenkins - 无法加载 Jenkins 共享库
- regex - Perl - 变量插值和反冲(转义)如何在替换正则表达式中工作,特别是替换部分
- python - 我收到与日志记录相关的此错误
- python - MatMul 时出现无效参数错误,当将 keras cnn 中的 2 个张量与注意力相乘时
- javascript - 我用 javascript 和 php 创建了一个简单的 spa,但在新选项卡中打开页面不会加载样式和脚本
- python - 将一个列表列表的元素分配给另一个列表列表的元素,同时保持总和约束
- python - 使用python获取Jenkins用户的用户权限
- flutter - 在 Flutter 中全局设置后备字体