0

我使用以下代码捕获屏幕,然后将其存储在 sdcard 中并转到另一个活动。但是当我导航到另一个活动时非常慢。我该如何解决?请问有人可以帮我吗?

  View v1 = view.getRootView();    
   v1.setDrawingCacheEnabled(true);    
bitmapBcfhForm3 = v1.getDrawingCache();    
File imagesFolder = new File( Environment.getExternalStorageDirectory(), "Signatures");

            imagesFolder.mkdirs();    
            String fileName = "bitmapBcfhForm3"+AppointmentDetails.getPatientId+".png";
            File out = new File(imagesFolder,fileName);
            FileOutputStream mFileOutStream1 = new FileOutputStream(out);
            bitmapBcfhForm3.compress(Bitmap.CompressFormat.PNG, 90, mFileOutStream1); 
            mFileOutStream1.flush();
            mFileOutStream1.close();
            }
                catch (Exception e) {
                    // TODO: handle exception
                    Log.v("log_tag", e.toString()); 
                }   
         startActivity(new intent(A.this.B.classs));
4

2 回答 2

0

您正在截屏并将其保存到 ExternalStorage,此过程将阻止您的 UI 线程,因此请尝试在单独的工作线程中进行截屏并保存功能;为此,您可以使用简单的 Thread 对象,或者用户 AsyncTask

于 2013-04-22T07:36:16.960 回答
0

我建议您在另一个线程中执行捕获和保存任务。因为最好的选择是AsycTask

检查这篇文章,搜索并学习 Asynctask 的工作。

快乐编码:)

于 2013-04-22T07:43:32.600 回答