New Activity Fails in Async

58 views Asked by At

My Application is crashing when I try to start new Activity. Need Help!

LoginAysnc logins = new LoginAysnc((Context) con);
logins.execute(); 



class LoginAysnc extends AsyncTask<Void, Void, String> {

    public LoginAysnc(Context context){
        contexts = context;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
            startActivity(new Intent(contexts.getApplicationContext(),home.class));

    }
3

There are 3 answers

0
Saritha G On

start your activity like:

startActivity(new Intent(CurrentActivity.this,NewActivity.class));

0
Roger On

Maybe you should call the method

@Override
protected String doInBackground() {
    // Your code to execute here
    return s;  // This is the String you get as a parameter in onPostExecute
}

That is the whole point of the AsyncTasks. Then your code in onPostExecute will get called. But I agree that you should post your LogCat to see what's wrong

1
thedarkpassenger On

Simply pass the Context instead of the Application Context.

startActivity(new Intent(contexts,home.class));

And check if you declared home activity in the Manifest.