我正在从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
未显示。谁能发现任何东西?
答案 0 :(得分:0)
你可以把你的Toast消息放在实现runOnUI()线程的内部,以便在正确的应用程序线程中显示警告,尝试并且可以工作。此致