0

我正在从 main_activity 打这个电话

Intent createAccount = new Intent(mainact_Context,Register_activity.class);
startActivity(createAccount);

这是调用的活动AsyncTask

public class Register_activity extends Activity {
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        context = this;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_activity);
        Button RegButton = (Button) this.findViewById(R.id.Regbutton);

        RegButton.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {

                RegisterWithServer regser = new RegisterWithServer(context);
                regser.execute();

            }

        });

        setupActionBar();
    }
}

在我的异步活动中,我有这个:

public class RegisterWithServer extends AsyncTask <String,Void,String> {

    Context con;

    public RegisterWithServer(Context context)
    {
        con = context;
    }

    protected String doInBackground(String... params) {

        //this code gets executed perfectly
    }

    @Override
    protected void onPostExecute(String result)
    {
        /*I tried doing something with the context and the result string here and it worked too.*/
        Toast.makeText(con, result , Toast.LENGTH_SHORT).show();
    }
}

doInBackground()部分得到完美执行。该onPostExecute()部分被调用但未Toast显示。任何人都可以发现任何东西吗?

4

1 回答 1

0

您可以将 Toast 消息放在实现 runOnUI() 线程中,以便在适当的应用程序线程中显示警报,尝试它并会起作用。问候

于 2014-05-13T15:24:59.410 回答