开发者

Why doesn't my Toast show up?

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

public void onCreate(开发者_StackOverflow社区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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜