简体   繁体   中英

Android AsyncTask & starting new Activities

I've been having some issues with starting a new activity once an AsyncTask has completed. I've read that I can put code like this:

protected void onPostExecute(String result) {
    super.onPostExecute(result);
    if (progress.isShowing()) {
        if (result.equals("true")) {
            progress.dismiss();
            activity.startActivity(new Intent(activity, Main.class));
        }
    }
}

But basically that just crashes and it's always on the line which it's starting the Activity, It comes up with the error NullPointerException but I can't figure out why?

Any idea?

Thanks Chris

检查以确保activity不为null ,因为它可能是NullPointerException的原因。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM