为什么我的吐司显示? [英] Why doesn't my Toast show up?

查看:155
本文介绍了为什么我的吐司显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敬酒不露面后才文件完成下载(我评论的下载功能)。任何想法,为什么?

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    ImageView的main_image_view =(ImageView的)this.findViewById(R.id.main_image_view);
    TextView的text_view =(TextView中)this.findViewById(R.id.main_text_view);    上下文的背景下= getApplicationContext();
    CharSequence的文字=找不到档案下载...请耐心等待,这是一个大的文件!
    INT持续时间= Toast.LENGTH_SHORT;    吐司面包= Toast.makeText(背景,文本,持续时间);
    toast.show();    //这个功能从一个URL的文件。
    大脑= get_frame_fl(FILE_NAME,mActive_slice);
    brain_slice = Bitmap.createBitmap(brain_pixels,FRAME_WIDTH,frame_height,Bitmap.Config.ARGB_8888);    //显示
    main_image_view.setImageBitmap(brain_slice);
}


解决方案

我觉得当你做 toast.show()你的请求的该UI线程显示敬酒消息。它不一定执行immediatley。那么你正在做一个文件下载执行在UI线程长时间运行的操作。直到它完成,这将阻止用户界面。我将你的文件的下载移动到的AsyncTask ,以便它不挂的用户界面。

My toast doesn't show up until after the file has completed downloading (I commented the download function). Any ideas why?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView main_image_view = (ImageView)this.findViewById(R.id.main_image_view);
    TextView text_view = (TextView)this.findViewById(R.id.main_text_view);

    Context context = getApplicationContext();
    CharSequence text = "File Not Found. Downloading... Please be patient, it's a large file!";
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();

    // This function fetches a file from a URL.
    brain = get_frame_fl(file_name, mActive_slice);
    brain_slice = Bitmap.createBitmap(brain_pixels, frame_width, frame_height, Bitmap.Config.ARGB_8888);

    // display
    main_image_view.setImageBitmap(brain_slice);
}

解决方案

I think when you do toast.show() you are requesting that the UI thread display a toast message. It doesn't necessarily execute immediatley. You are then performing a long running operation in the UI thread by doing a file download. This will block the UI until it completes. I would move your file download into an AsyncTask so that it does not hang the UI.

这篇关于为什么我的吐司显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆