I am trying to launch an activity in the onPostExecute method of an AsyncTask. This async class is implemented in another class which dosent extends an activity. But I am passing application context as an argument to the method in this c开发者_高级运维lass. Here is the sample code
@Override
protected void onPostExecute(String result)
{
try
{
System.out.println("Response : "+result);
Toast.makeText(context, "Account Successfully Created", Toast.LENGTH_LONG).show();
Intent intent = new Intent(context,OperationPanelActivity.class);
context.startActivity(intent);
}
catch(Exception e)
{
Log.d("Error: ", e.getMessage());
}
}
Inside this class I am taking the application context like this
public void createUser(String userName,String password,String firstName,String lastName,String email,Context context)
{
InvokeWebService service = new InvokeWebService();
CALL_URL = Global.SERVICE_URL+"createuserget";
this.context = context;
service.execute(new String[] {userName,password,firstName,lastName,email});
}
But the new activity is not getting invoked.
How can I do this in android? Thanks
This is because your activity could be finished by the time you run onPostExecute. You should notify the activity somehow and let the activity start the new activity
精彩评论