Last active
August 17, 2019 12:02
-
-
Save jsaund/138101774f31a30537b3f6cb78861217 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity { | |
| private static final String IMAGE_URL = "https://www.android.com/static/2016/img/logo-android-green_2x.png"; | |
| private ProgressBar progressIndicator; | |
| private ImageView imageView; | |
| private Handler handler; | |
| class ImageFetcher implements Runnable { | |
| final String url; | |
| ImageFetcher(String url) { | |
| this.url = url; | |
| } | |
| @Override | |
| public void run() { | |
| // download image -- code removed | |
| final Bitmap bitmap = BitmapFactory.decodeStream(inputstream); | |
| handler.post(new Runnable() { | |
| @Override | |
| public void run() { | |
| imageView.setImageBitmap(bitmap); | |
| } | |
| }); | |
| } | |
| } | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| final Thread workerThread = new Thread(new ImageFetcher(IMAGE_URL)); | |
| workerThread.start(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Missing
handlerinitialization on main Thread. i.ehandler = new Handler()