Communicating between two lists

Next problem:

I have two lists on one activity: one to select from and one with results. When  selection is clicked, how to I make list one to update?

Looking for sources.

1. This is example of using thread communication with Handler class


More later. Have to go. (didn;t work most of yesterday either..)

Progress indicator – not solved

I’d like to add “Wait” indicator to some longer running operations, like loading bitmaps and reading from server.

Let’s gather info


has example of activity with a progress bar that can be shown and updated during execution of background thread

I don’t want to replace activity, I just want a “wait” indicator


ProgressDialog dialog = new ProgressDialog(this);


if (dialog.isShowing()) {


 with setProgressStyle(STYLE_SPINNER)

This seems to be easy to implement. However this dialog doesn't come up. Why? 


You need to request this as a feature near the top of the onCreate() method of your Activityusing the following code:


Then turn it on like this:


and turn it off like this:


3. I liked this:
define invisible area in the layout: and the toggle visible/Gone when you need to


android:visibility=”gone” >

android:layout_height=”wrap_content” >

None of these works for me. I get nothing, no bar or spinner. 
Only time i get spinning circle is if I put it in ocCreate and put the start pinning right there.  
This must be something wrong on my side, because instructions are clear.

android mark has been invalidated

Created by Jason Hise with Maya and Macromedia...

Created by Jason Hise with Maya and Macromedia Fireworks. A 3D projection of a 5-cell performing a simple rotation. (Photo credit: Wikipedia)

Bitmaps still giving me problems.

Earlier on I created code that scales bitmaps down “well enough” with rough measurements. It was ok for larger bitmaps but didn’t work well for smaller images found in gallery. Most obvious this became when I implemented nice zoom window.  This window initially shows bitmap in it’s size whatever is stored. Sometimes it’s nice (for camera images) and sometimes it’s tiny.

Let’s fix it.

Android dev guide recommends two steps: measure with options.inJustDecodeBounds = true and scale with options.inJustDecodeBounds = false.

That’s awesome but the stream is used up on a first pass.

Calling stream.reset()  gives error.

Wrapping stream into BufferedStream (makes sense at first) leads to a similar issue. Buffered stream can have marks


However for larger images (camera) i get error Mark has been invalidated.

So let’s try this: use mark. But if exception hits I will re-open the Uri.

// this gives error for larger images taken by camera
} catch(IOException e){
options.inPreferredConfig = Config.RGB_565;
options.inSampleSize = 8;
imageStream = activity.getContentResolver().openInputStream(
is = new BufferedInputStream(imageStream);

This is working for both small and large images.

Leaving this for now.  Do you have a better idea? Write to me.


Android back button

Android has built in back button. When I am in any activity user can press a back button just like in browser. If there is partial data entered it will be lost (good), if there is partial data saved it will be left dangled (not good).

I want to capture back button event and do preps.

This captures back button event:

public void onBackPressed(){
Log.d(TAG, “back button is pressed”);
// do something

What is something to do? I decided to set RESULT_OK and call finish().

My receiving activity recognizes that all has been taken care of (OK) and refreshes the screen.



Creating background image for the app

What size is required for all devices

What is image quality requirement

Should I create separate images for each of screen sizes?

Do I have to worry about all these?

Let’s collect data:

1. The following are the best dimensions for the app to run in all devices.

xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px

2. What is small, med, large..  for screens?
  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp

3. This article explains screen sizes

So let’s see. I have one image (of golden gate bridge). Let’s try to adopt it for my app as experiment.

Opened my image in Gimp. My image is 480×640 px which is good enough only for ldpi and mdpi.  WFT is my emulator?

Resized canvas to 320x480 (preserve aspect ratio) and placed to mdpi. What's going to happen? Image size of png became 267K (up from 71K jpg). Why is that? 

Startup time is higher. My imaged came up but.. I can see only around sides which is correct. Such a waste! I have to put close to 1M of image to see nicer picture around the borders of the app. No way that it’s a best we could do! Is it?  Anyone?

Next experiment. Maybe I create a gradient background and leave it as is. Maybe will place an image to lower third.

<?xml version=”1.0″ encoding=”utf-8″?>
<selector xmlns:android=””&gt;
android:type=”linear” />

Result: using this selector file as drawable for background creates a gradient vertically. I don’t understand that that 90 degrees is about.

What’s this linear? Let’s try radial.  That crashed the app. Ok, that’s for crashing the app. : )

– People recommend to do this , I don’t know yet why..


Ok winner!!! I can do gradient background overlayed with an image on a bottom right:

<?xml version=”1.0″ encoding=”utf-8″?>
<layer-list xmlns:android=””&gt;
android:type=”linear” />
<item android:top=”400dp” android:left=”200dp”
android:right=”10dp” >

 or this one:

<?xml version=”1.0″ encoding=”utf-8″?>
<layer-list xmlns:android=””&gt;
android:type=”linear” />
<item >
android:tileMode=”disabled” android:gravity=”bottom|right” >



I want to see a prompt for my EditText boxes with all strings that user already entered in previous sessions. All these data is captured in my database, that’s not a problem. How to do the UI?

1. I came across this excellent post

That’s it.  Implemented as described without flaws. BTW my style for EditText still applies for


However not as fast. This works on emulator and does absolutely nothing on device. Grrr!!
2. Found this tutorial
Will have to read and follow. Oh men..

Startup performance

My app is taking a bit longer to start than I want to. Yes, there is lots of code and lot of Log.d statements.

Let’s see what I can do.

1. Turned off Log statements. I had it tooled to be able to turn all Log on and off.

Faster? Gmm questionable.

2. Have to tame more code out to another thread.   That’s the key.

3. looked into proper use of graphics, i’m ok.  Got all my icons done with Android Studio.  (Iconology, then follow links)


Take care. Do things right from the first time.