Skip to content Skip to sidebar Skip to footer

Navigation Drawer Stuck When Offline Data Loading

I am developing news app user can download video and image. So I developed navigation drawer with different fragment with material design. But I am facing some problem in it when

Solution 1:

In your AsyncTask, you are accessing the class fields of the Fragment! This will actually block the UI Thread :-(

The lines

videofiles = new ArrayList<>();imagefiles = new ArrayList<>();

cannot be there. You need to create local lists, put data in them and then return it in onPostExecute().

Start by replacing

publicclassLoadOfflineDataextendsAsyncTask<Void, Void, Void> {

with

publicstaticclassLoadOfflineDataextendsAsyncTask<Void, Void, Void> {

This will give you errors in places you need to change :-)

Solution 2:

I found the answer.

It is in my RecyclerAdapter when i get thumbnail using inbuilt class so it will take time to set it see my

Old code

Bitmap bmThumbnail;

//MICRO_KIND, size: 96 x 96 thumbnail
       bmThumbnail = ThumbnailUtils.createVideoThumbnail(sdcard_path + "/Botad News/Videos/" + fileName, MediaStore.Images.Thumbnails.MICRO_KIND);
        holder.img_main.setImageBitmap(bmThumbnail);

New code is using glide library so lib automatically handle the thread i assume.

 BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
        int microSecond = 6000000;// 6th second as an example
        VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond);
        FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888);
        Glide.with(context)
                .load(sdcard_path + "/Botad News/Videos/" + fileName)
                .asBitmap()
                .override(250,250)// Example
                .videoDecoder(fileDescriptorBitmapDecoder)
                .into(holder.img_main);

Found solution HERE....

Post a Comment for "Navigation Drawer Stuck When Offline Data Loading"