【发布时间】:2013-11-22 11:04:17
【问题描述】:
我想在 doInBackground 方法的后台线程中显示一个 Toast。当然,这是行不通的。所以我尝试了这个
int error = 1;
publishProgress(error);
Log.i ( "InternetConnection" , "Loading Internet from Cache not working because of no Internet connection." );
return null;
而onProgressUpdate方法是
protected void onProgressUpdate ( Integer integers ){
if ( integers == 1){
Toast.makeText ( c.getApplicationContext(), "Daten konnten nicht geladen werden.", 0).show();
}
}
是不是,当我调用 publishProgress 时使用了 onProgressUpdate ?
C 是我的活动,所以
Context c = MainActivity();
我怎么可能显示 Toast,因为这段代码没有显示出来。
【问题讨论】:
-
使用日志,或将数据发送到 postExecute 以显示在 ui 上
-
我正在登录。对于看不到日志的用户,它应该是可见的。敬酒是我想做的事。不想将其作为静态文本显示给用户。
-
@Rohit 您可以在
onProgressUpdate()方法中处理 UI 内容,该方法也运行在 UI 线程上。
标签: android android-asynctask toast android-toast