Search code examples
androidbitmaprecoverminimization

How to restore bitmap after application minimization?


I have a drawing application. I need the application to recover from minimization (clicking back until the application minimizes). As i understood from several forums the best way and the simplest to do it is by saving the bitmap to a local temporary folder, and on open the bitmap from it. What i didn't find is any tutorial or examples how can it be done.

Can you please suggest some good tutorial on this issue or maybe in case you have done such a thing before post your solution to this issue.

Thanks,


Solution

  • Better to use Android SharePreference to Store Image Bitmap.

    Save Image Bitmap.

    public boolean saveImage(Context context, Bitmap realImage) 
    {
        Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
    
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        realImage.compress(Bitmap.CompressFormat.JPEG, 100, baos);   
        byte[] b = baos.toByteArray(); 
    
        String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
    
        editor.putString("FacebookImage", encodedImage);
        return editor.commit();
    }
    

    Get Image Bitmap

     public Bitmap getImageBitmap(Context context)
        {
             Bitmap bitmap = null;
             SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
             String saveimage=savedSession.getString("FacebookImage", "");
             if( !saveimage.equalsIgnoreCase("") ){
                    byte[] b = Base64.decode(saveimage, Base64.DEFAULT);
                     bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
                }
            return bitmap;
        }
    

    After get Image bitmap show it image view or other view.

    Thanks