2

By using information in stackoverflow I finally could write a code that receive an image from URL and set it as hamburger menu icon in navigation drawer by using Picasso . It works very well . But still there is a problem : ( when installing the app for the first time and run it ) OR ( when turning off the mobile and then rerun the app ) , the icon is not shown . When rerun the app ( before turning off the mobile ) , the app run correctly and icon is shown . How I can solve this problem?

 {
            final Target mTarget = new Target() {
                @Override
                public void onBitmapLoaded(Bitmap bitmap,Picasso.LoadedFrom loadedFrom) {
                    Log.d("DEBUG", "onBitmapLoaded");
                    Bitmap scaledBitmap =  Bitmap.createScaledBitmap(bitmap, 100, 100, false);
                    mBitmapDrawable = new BitmapDrawable(getResources(), scaledBitmap);
                    getSupportActionBar().setHomeAsUpIndicator(mBitmapDrawable);

                }

                @Override
                public void onBitmapFailed(Exception e, Drawable errorDrawable) {
                }    
                @Override
                public void onPrepareLoad(Drawable drawable) {
                    Log.d("DEBUG", "onPrepareLoad");
                }
            };


 Picasso.get().load("http://192.168.1.53:8080/Farid/1.jpg").into(mTarget);             
   }    
            getSupportActionBar().setHomeButtonEnabled(true);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Farid Abdi
  • 99
  • 1
  • 11

1 Answers1

0

You may create a local cache for the icon, after downloaded the icon you might convert it to float and store it in sharePreference, when the icon cannot load, you might convert the cached icon from float to bitmap from sharePreference. This thread might help you Store bitmap to SharePreference

Lazy boy
  • 24
  • 3