user1684645
user1684645

Reputation: 19

Long wait when starting new activity in Android

I have two activities in my Android app.

1) A list which shows items

If the user clicks on one item it opens activity 2

2) Shows a big image of the item

Now, when I click on an item and thus start the second activity there are a few seconds which the app needs to start the activity. (I suspect because of the image it needs to load). This completely destroys the flow of the use case.

What is the best practice to deal with this?

Upvotes: 0

Views: 103

Answers (2)

sanket
sanket

Reputation: 77

In Second Activity use new Thread.. like below

 new Thread(new Runnable() {
                @Override
                public void run() {
                    //here put your code
                    runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                      //here set your image.
                    }
                  });
                }
            }).start(); 

Upvotes: 0

Mustansar Saeed
Mustansar Saeed

Reputation: 2790

Loading Bitmaps on Main UiThread takes time so you have to load your bitmaps off the Ui Thread. Use the Universal Image Loader for loading/caching the bitmaps. See the link https://github.com/nostra13/Android-Universal-Image-Loader

ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance
// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view 
//  which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView);

Hope this helps.

Upvotes: 1

Related Questions