Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing image in imageview using Threads

I'm getting error with this code. Why huhu 123123123

Thread timer = new Thread()
{
    public void run()
    {
        try
        {
            sleep(1500);
            splash.setImgeResource(R.drawable.dilclogo);
            sleep(1500);
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
        finally
        {
            Intent intent = new Intent(MainActivity.this, MenuScreen.class);
            startActivity(intent);
        }
    }
};
timer.start();
like image 587
Thea Johnson Avatar asked Aug 25 '26 14:08

Thea Johnson


1 Answers

This is because you can NOT access your UI/Main thread directly from any other thread. You can use below methods to access your UI thread though:

  1. Using AsyncTask
  2. Using runOnUiThread()

You can also read this article on threading in android to help you understand this concept better.

like image 108
Gagan Avatar answered Aug 28 '26 06:08

Gagan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!