加载屏幕后运行图库完成加载

时间:2012-11-27 13:38:41

标签: android image-gallery

我目前刚接触Android。我见过很多情况,加载屏幕可以启动文件下载。我想知道当加载屏幕完成处理后台任务时,我怎么可能在postexecute()命令上启动库。 以下是后台任务中的代码。我想在这个背景中编写代码以便库在postexecute()上执行,或者我还有什么方法可以做到这一点。

P.S我的加载屏幕和图库位于不同的java文件中。那么有什么方法可以让我们在postexecute命令加载屏幕后立即运行画廊?

由于

  //The code to be executed in a background thread.
            @Override
            protected String doInBackground(String... strings) 
            {
                /* This is just a code that delays the thread execution 4 times, 
                 * during 850 milliseconds and updates the current progress. This 
                 * is where the code that is going to be executed on a background
                 * thread must be placed. 
                 */
                try 
                {
                    //Get the current thread's token
                    synchronized (this) 
                    {
                        //Initialize an integer (that will act as a counter) to zero
                        int counter = 0;
                        //While the counter is smaller than four
                        while(counter <= 4)
                        {
                            //Wait 850 milliseconds
                            this.wait(850);
                            //Increment the counter 
                            counter++;
                            //Set the current progress. 
                            //This value is going to be passed to the onProgressUpdate() method.
                            publishProgress(counter*25);
                        }
                    }
                } 
                catch (InterruptedException e) 
                {
                    e.printStackTrace();
                }
                return null;
            }

            //Update the TextView and the progress at progress bar
            @Override
            protected void onProgressUpdate(Integer... values) 
            {
                //Update the progress at the UI if progress value is smaller than 100
                if(values[0] <= 100)
                {
                    tv_progress.setText("Progress: " + Integer.toString(values[0]) + "%");
                    pb_progressBar.setProgress(values[0]);
                }
            }

1 个答案:

答案 0 :(得分:0)

是的,你可以。只需从PostExecute启动画廊。

   @Override
        protected void onPostExecute(Void...values) 
        {
            //get image path
            File file = <imageFilepath>;
             //add to intent
        Intent intent = new Intent(Intent.ACTION_VIEW);
            //start activity
        intent.setDataAndType(Uri.fromFile(file),"image/*");
            startActivity(intent);
        }