【发布时间】:2014-10-09 11:22:48
【问题描述】:
请分享如何在 doinbackground() 或 onpostexecute() 方法 Asynctask 类中使用 Intent。当我尝试使用这些代码时,它会显示错误。
Intent intent = new Intent(asynctask.this, home.class);
startActivity(intent);
finish();
private Class<Home> clazz;
public asynctask(Class<Home> clazz){
this.clazz = clazz;
}
Asynctask doInBackground() 方法:
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(this, clazz);
startActivity(intent);
finish();
Toast.makeText(cxt, "welcome", Toast.LENGTH_SHORT).show();
return null;
}
【问题讨论】:
-
asynctask你的活动吗? -
您必须始终在 onPostExecute() 方法中使用 Intent.. 并且不要在 doInBackground() 中使用 toast,Toast 应该可能是它在您的代码中给出错误并请发布您的 logcat ..
-
请清楚地告诉我是 android 新手,我不知道 asynctask 类函数。
标签: android android-intent android-asynctask