Temp storage for bitmap

by m_vitaly » Wed, 14 Oct 2009 04:45:06 GMT

Sponsored Links
 My program creates a bitmap and successfully stores it on external
storage (Images.Media.EXTERNAL_CONTENT_URI).

The next option to implement is to share the image.
I'm thinking about different way of doing it:
1. Save it as captured image (as before) and startActivity with
Intent.ACTION_SEND intent with the saved image uri.
2. Save it in application's home directory (getFileStreamPath()),
startActivityForResult as in 1. and I hope that I'll recieve a result
when the message is sent.
3. Save it in some kind of temp/cache folder and don't bother about
deleting it or delete it as in 2.

Personally I prefer the second option.

My questions are:
Will it work with startActivityForResult() as in 2. ?
Do I have access to temp/cache folder as in 3. ? If I do, Should I
delete the file afterwards ?
May be some flag for Intent.ACTION_SEND to delete the file
afterwards ?



Temp storage for bitmap

by Streets Of Boston » Wed, 14 Oct 2009 10:21:37 GMT

 When you store it in the EXTERNAL_CONTENT_URI, your image can already
be shared with every other app on the phone.

When you added (inserted) the image, your result was a Uri. This Uri
can be used by any other app to obtain your image.


Sponsored Links

Temp storage for bitmap

by m_vitaly » Wed, 14 Oct 2009 22:03:21 GMT

 Ok, but what if I want to delete if after issuing startActivity, can I
do this ?
And where should I store it then ?


Temp storage for bitmap

by Streets Of Boston » Tue, 20 Oct 2009 06:53:11 GMT

 You can delete it while handling the onActivityResult (this method is
called after your sub/child activity finishes).


Temp storage for bitmap

by Vitaly Polonetsky » Tue, 20 Oct 2009 21:03:50 GMT

 Thanks for your reply, that's what I'm planing to do.My other question was
where do I temporary store the image ?
I can store it in EXTERNAL_CONTENT_URI, Context.getCacheDir() or
Context.getFilesDir() ...
But what's preferable and why ? (considering: deletion timing, permissions,
locks, etc.)
Personally, I would choose cache dir.

On Tue, Oct 20, 2009 at 12:52 AM, Streets Of Boston <flyingdutc...@gmail.com

Best regards,
Vitaly Polonetsky


Temp storage for bitmap

by Streets Of Boston » Tue, 20 Oct 2009 22:24:25 GMT

  had a similar issue with storing temporary images (saving color-
corrected images).

It turned out that storing a temp image (just plain binary data; a
large array of int-s (ARGB)) on the SD-card was the fastest (still
slow, though).

Storing it on the phone, the cache (getCacheDir) or data
(getFilesDir), was way slower (about 2 times for writing) than storing
it on the SD-card. Note that i have a class-6 SD-card in my phone.

Another reason to use the SD-card instead of the cache is the limited
amount of phone-memory. Android will clear the cache when necessary,
but stil....

I call Bitmap.getPixels a number of times on a *large* bitmap, using a
temporary buffer, and write the contents of this buffer to a
FileOutputStream that points to a temp file on the SD-card. If you
have a *small* bitmap, just calling 'compres's using the PNG (no image-
quality loss) is sufficient.

Be sure to not assign an image extension (e.g ".jpg" or ".png") to the
name of this temporary file... it may show in the Gallery app :-)

On Oct 20, 9:02am, Vitaly Polonetsky <topix...@gmail.com> wrote:

Other Threads

1. why thread died? need background thread..

bellow just a test sample source for a background thread.

i would like that when my app is closed it still run in the background
(like at my tracks) to collect data even when it is closed.

but it always dies after a while by itself, why?


package com.chris.alarmer;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class alarmer extends Activity {
    /** Called when the activity is first created. */

    public void onDestroy() {
        Thread thr = new Thread(null, mTask, "alarmer");

    public void onCreate(Bundle savedInstanceState) {

        Thread thr = new Thread(null, mTask, "alarmer");


    Runnable mTask = new Runnable() {
        public void run() {
            // Normally we would do some work here...  for our sample,
we will
            // just sleep for 30 seconds.
                Log.i("DATABASE-TEST","-----------: START THREAD");
                long endTime = System.currentTimeMillis() + 99999*1000;
                long endTime2 = System.currentTimeMillis() + 10*1000;

            while (System.currentTimeMillis() < endTime)
                //get data after 10 seconds
                if (System.currentTimeMillis() > endTime2)
                        endTime2 = System.currentTimeMillis() +10*1000;
                        Log.i("DATABASE-TEST","-----------: GET DATA");


            Log.i("DATABASE-TEST","-----------: END THREAD");
            // Done with our work...  stop the service!
          //  alarmer.this.stopSelf();


2. Good size for picture background

I have an application that has a picture for the background.  The
picture is pretty large.  I want to shrink it down so it won't use so
much memory.  I also am having a problem if the orientation changes, the
program crashes.  However I am sure I know how to fix that part.  So all
I really want to know is a good rule of thumb to picture size in pixels
that will work on most phones.


3. API demos and SDK 1.5: is available?

4. Adding onClickListener and OnTouchListener to a Button

5. Intent.ACTION_PICK and gif image

6. how to launch terminal emulator apk from new sdk-1.5 (cupcake)

7. xml view defination to take event handler class name