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);
}
};