title: Android - Why won't my Toast message show?
body: <p>My toast doesn't show up and I am confused because I think I made it correctly, I don't understand.  As you can see its a program that shows three buttons, the first one activates a download which is supposed to open the PDFs file automatically - if there is no pdf reader a toast should pop up saying there isn't a reader.  the other buttons take to a new screen and operate as a back button.  </p>
  
  <pre><code>public class myactivity extends Activity {
  
  public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
  private Button startBtn;
  private ProgressDialog mProgressDialog;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.myactivity);
      mProgressDialog = new ProgressDialog(myactivity.this);
      mProgressDialog.setMessage("Please be patient, file downloading...");
      mProgressDialog.setIndeterminate(false);
      mProgressDialog.setMax(100);
      mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  
      Button Section = (Button) findViewById(R.id.Section);
      Section.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View view) {
              // TODO Auto-generated method stub
              Intent Section = new Intent(view.getContext(),
                      Section.class);
              startActivity(Section);
  
          }
      });
  
      Button Back = (Button) findViewById(R.id.Back);
      Back.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              // TODO Auto-generated method stub
              setResult(RESULT_OK);
              finish();
          }
      });
  
      startBtn = (Button) findViewById(R.id.Search);
      startBtn.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
              startDownload();
          }
      });
  }
  
  private void startDownload() {
      DownloadFile downloadFile = new DownloadFile();
      downloadFile
              .execute("http://www.website.com/document.pdf");
  
  }
  
  class DownloadFile extends AsyncTask&lt;String, Integer, String&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          mProgressDialog.show();
      }
  
      @Override
      protected void onProgressUpdate(Integer... progress) {
          super.onProgressUpdate(progress);
          mProgressDialog.setProgress(progress[0]);
      }
  
      @Override
      protected String doInBackground(String... aurl) {
          try {
  
              URL url = new URL(aurl[0]);
              URLConnection connection = url.openConnection();
  
              connection.connect();
              int fileLength = connection.getContentLength();
              int tickSize = 2 * fileLength / 100;
              int nextProgress = tickSize;
  
              Log.d(
  
              "ANDRO_ASYNC", "Lenght of file: " + fileLength);
  
              InputStream input = new BufferedInputStream(url.openStream());
  
              String path = Environment.getExternalStorageDirectory()
                      + "/Android/Data/"
                      + getApplicationContext().getPackageName() + "/files";
              File file = new File(path);
              file.mkdirs();
              File outputFile = new File(file, "test1.pdf");
  
              OutputStream output = new FileOutputStream(outputFile);
  
              byte data[] = new byte[1024 * 1024];
              long total = 0;
              int count;
              while ((count = input.read(data)) != -1) {
                  total += count;
                  if (total &gt;= nextProgress) {
                      nextProgress = (int) ((total / tickSize + 1) * tickSize);
                      this.publishProgress((int) (total * 100 / fileLength));
                  }
                  output.write(data, 0, count);
              }
  
              output.flush();
              output.close();
              input.close();
              showPdf();
  
          } catch (Exception e) {
          }
          return null;
      }
  
  }
  
  private void showPdf() {
      // TODO Auto-generated method stub
      mProgressDialog.dismiss();
  
      File file = new File(Environment.getExternalStorageDirectory()
              + "/Android/Data/" + getApplicationContext().getPackageName()
              + "/files/test1.pdf");
      Intent testIntent = new Intent(Intent.ACTION_VIEW);
      testIntent.setType("application/pdf");
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_VIEW);
      Uri uri = Uri.fromFile(file);
      intent.setDataAndType(uri, "application/pdf");
      try {
          startActivity(intent);
      } catch (ActivityNotFoundException e) {
          Toast.makeText(myactivity .this,
                  "No Application Available to View PDF", Toast.LENGTH_LONG).show();
      }
  
  }
  
  }
  </code></pre>