Why doesn't my toast appear?

My toast does not appear until the file completes the download (I commented on 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 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); } 
+4
source share
1 answer

I think when you do toast.show() , you are requesting the UI thread to display toasts. This is not necessarily done immediately. Then you perform a lengthy operation on the user interface thread, loading the file. This will block the user interface until it is completed. I would move the file to the AsyncTask file AsyncTask that it does not freeze the user interface.

+21
source

Source: https://habr.com/ru/post/1337997/


All Articles