簡體   English   中英

新活動在異步中失敗

[英]New Activity Fails in Async

當我嘗試啟動新活動時,我的應用程序崩潰了。 需要幫忙!

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

    }

也許你應該調用該方法

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

這就是AsyncTasks的重點。 然后您的onPostExecute中的代碼將被調用。 但是我同意您應該發布LogCat來查看問題所在

只需傳遞Context而不是應用程序上下文。

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

並檢查您是否在Manifest聲明了home activity

開始您的活動,例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM