1

I'm trying to have a progress dialog pop up after a user clicks on an icon, so that they are aware that the next activity (a Tag Scanner) is starting. The problem is that the progress dialog only pops up when the phone is in landscape orientation and even then the spinner isn't spinning. I've noticed that the dialog pops up sometimes in portrait orientation but it's rare and usually out of focus. I don't have control over the Tag Scanner code (the second Activity), so starting the progress dialog there is not an option. Here is the relevant code, any ideas on what to do? I've tried to start the progress dialog from the onOptionsItemSelected method but I have the same problem. I've also tried starting it from within myTask and same issue. Really lost here, any help would be appreciated

public boolean onOptionsItemSelected (MenuItem item){
switch (item.getItemId()){
      case R.id.menu_scanner:
          ProgressDialog progress = new ProgressDialog(this,R.style.MyDialog);  
          new MyTask(progress).execute();
      break;
}
return false;
}

public class MyTask extends AsyncTask<Void, Void, Void> {
      private ProgressDialog progress;

    public MyTask(ProgressDialog progress) {
        this.progress = progress;
      }

      public void onPreExecute() {
          progress.setMessage("Loading Tag Scanner...");
          progress.show();
          progress.setCancelable(true);

      }

      public void onPostExecute(Void unused) {


          TagContext.getInstance().initialize(APP_KEY, APP_VERSION, getApplicationContext());
          TagContext.getInstance().launchViewfinder(                
                    MainActivity.this,   //Pass the parent activity for the viewfinder
                    listener,       //Pass the listener to use for handling callbacks.
                    null);
          progress.dismiss();             
      }

    @Override
    protected Void doInBackground(Void... arg0) {       
        return null;
    }
    }
Art
  • 223
  • 2
  • 8
  • You have to display that dialog in the TagContext activity, there's no other way – Alexander Kulyakhtin Apr 21 '13 at 06:15
  • put a super.onPostExecute(unused) and progress.dismiss(); first in onPostExecute() – Raghunandan Apr 21 '13 at 06:18
  • What is `TagContext`? – Squonk Apr 21 '13 at 06:24
  • Tried putting super.onPostExecute(unused) and progress.dismiss(); first in onPostExecute() but still the same problem :S TagContext is the context of the second Activity. It's Microsoft's Tag scanner, but I don't have the source code for that, just a jar file :( – Art Apr 21 '13 at 06:27
  • @Art, A very interesting implementation of AsyncTask, what's it for? You're doing nothing in doInBackground(), so there's no point in having this AsyncTask at all. – Egor Apr 21 '13 at 07:34
  • @Egor Basically I have no control of the second Activity code, so I can't dismiss or start the progress dialog then. The problem is launching the second Activity (the TagContext.getInstance().launchViewfinder...) takes time, so I want the user to be aware that something is happening. Therefore I want to have a progress dialog when the user clicks on the "scanner icon" (that launches the second activity). This is the only way I saw how to do it. Would you have a better method? – Art Apr 21 '13 at 15:14

0 Answers0