我Activity里开启了一个线程,用它来弹出一个对框,可是弹不出来,这是怎么回事?而且Toast也是没有用的。
代码如下:
new Thread()
{
@Override
public void run()
{
Looper.prepare();
try
{
if (!Utility.CheckNetWorkStatus(NewVersionActivity.this))
{
Toast.makeText(NewVersionActivity.this,
"网络连接断开,请检查网络连接", 1000).show();
return;
}
URL url;
url = new URL(mUrl);
URLConnection conn = url.openConnection();
Log.i("upgrade", "open connection to get file size!");
conn.setRequestProperty("Charset", "UTF-8");
fileSize = (long) conn.getContentLength();
AlertDialog.Builder dialog = new AlertDialog.Builder(NewVersionActivity.this);
dialog.setTitle(R.string.tips);
dialog.setMessage(R.string.getsrcwrong);
dialog.setPositiveButton(R.string.ok,new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1)
{
}
});
dialog.show();
} catch (Exception e)
{
e.printStackTrace();
Log.e("Exception", e.toString()+" "+fileSize);
}
super.run();
}
}.start();
代码如下:
new Thread()
{
@Override
public void run()
{
Looper.prepare();
try
{
if (!Utility.CheckNetWorkStatus(NewVersionActivity.this))
{
Toast.makeText(NewVersionActivity.this,
"网络连接断开,请检查网络连接", 1000).show();
return;
}
URL url;
url = new URL(mUrl);
URLConnection conn = url.openConnection();
Log.i("upgrade", "open connection to get file size!");
conn.setRequestProperty("Charset", "UTF-8");
fileSize = (long) conn.getContentLength();
AlertDialog.Builder dialog = new AlertDialog.Builder(NewVersionActivity.this);
dialog.setTitle(R.string.tips);
dialog.setMessage(R.string.getsrcwrong);
dialog.setPositiveButton(R.string.ok,new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1)
{
}
});
dialog.show();
} catch (Exception e)
{
e.printStackTrace();
Log.e("Exception", e.toString()+" "+fileSize);
}
super.run();
}
}.start();
解决方案 »
- 高分求教:startActivity后不显示要启动的activity,可以做到吗?
- android自带phone应用关闭问题
- make: *** No rule to make target libbluez-common-static.a
- android问题
- Android交流QQ群:96878376
- android adb shell思考,大家一起来
- Android中在哪里清理Application中的全局资源?
- TextView.fromHtml()图片等比放大后与下面的文字重叠
- 哥哥姐姐们求解惑。。。。
- 安卓上利用hook进行透明加解密
- 下载网络数据保存到SD卡中,大小总为2M
- 求android大神笼罩啊
你没有添加这个循环,当然显示不了了
任何线程都可以作为一个UI thread,不然,那么系统的toast是在哪里弹出的?系统service中怎么弹出ANR的dialog?