我有这个代码
public class AsyncClassTest extends Activity {
String strMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new MyClass().execute();
Toast.makeText(AsyncClassTest.this, strMessage, Toast.LENGTH_LONG)
.show();
}
public class MyClass extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
return "Hello world!!!";
}
@Override
protected void onPostExecute(String result) {
strMessage = result;
}
}
}
以及何时运行,在new MyClass().execute();
它显示strMessage
为 null 并且在显示 toast 代码进入onPostExecute()
方法之后,如何使此代码运行并在之后显示消息new MyClass().execute();