0

I am trying to launch a new intent after I have loaded data. I am using a handler that calls a method when the thread is complete and then in this method I am trying to launch a new Intent but my app is crashing every time. I have narrowed it down to the Context variable in the Intent constructor. Here is my code:

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        pDialog = new ProgressDialog(this);

        pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pDialog.setMessage("Loading...");
        pDialog.setCancelable(false);
        pDialog.show();

        mHandler = new Handler();
        checkUpdate.start();
    }

    private Thread checkUpdate = new Thread()
    {
     public void run()
     {
      try
      {
                        //Do some stuff

          mHandler.post(showUpdate);
      }
      catch(Exception e)
      {
       //Error case
      }
     }
    };

    private final Context context = this;        

    private Runnable showUpdate = new Runnable()
    {
     public void run()
     {
      //Do post process

      pDialog.dismiss();

                    //This is the line it crashes on
      Intent intent = new Intent(context, com.example.example1.TestListActivity.class);
         startActivityForResult(intent, 0);
     }
    };
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
rplankenhorn
  • 2,075
  • 2
  • 22
  • 32
  • I have also tried getApplicationContext() in the Intent constructor instead of context. So the other line would be: Intent mowerListIntent = new Intent(getApplicationContext(), com.example.example1.TestListActivity.class); – rplankenhorn Sep 30 '10 at 14:53
  • Without the exception from the log, all we can do is speculate. Also, how did you narrow down what was causing the issue? Are you positive it is not in the Activity receiving the Intent? – codelark Sep 30 '10 at 15:26
  • Alright the exception I keep getting is InvocationTargetException. I am trying to get the LogCat but for some reason it isn't outputting anything. I have it set on verbose and nothing comes up. – rplankenhorn Sep 30 '10 at 17:24
  • Also, it now appears to be getting passed the Intent line and actually launching the new ListActivity. In the ListActivity, I just have the onCreate method with the super call and I have commented out all of my other code and I still get the InvocationTargetException. – rplankenhorn Sep 30 '10 at 17:26

1 Answers1

1

I figured it out. Turns out I forgot to include the new Activity in the manifest file.

rplankenhorn
  • 2,075
  • 2
  • 22
  • 32