我在我的代码中实现了这样的AsyncTask。你能告诉我我是否正确使用了AsyncTask吗?感谢。
protected class AsyncTranslator extends AsyncTask<String, JSONObject, String>
{
@Override
protected String doInBackground(String... params) {
String mymeaning = null;
RestAPI api = new RestAPI();
try
{
JSONObject jsonObj = api.GetMeaning(params[0]);
mymeaning = jsonObj.toString();
}
catch (Exception e)
{
Log.d("Error", e.getMessage());
}
return mymeaning ;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
Toast.makeText(context, "Please wait.", Toast.LENGTH_SHORT).show();
}
@Override
protected void onPostExecute(String mymeaning) {
Log.d("onPostExecute", null);
Intent i = new Intent(SendMeaningActivity.this, ShowMeaningActivity.class);
i.putExtra("meaning", mymeaning);
startActivity(i);
}
}