[Android] Curious issue about notifications

It may seem obvious, but this issue annoyed me very much and made me waste some valious hours.

As scenario, imagine that you launch ActivityA, and after clicking a button, you launch ActivityB on top of it.

Now, ActivityB executes a long-time background operation (such as parsing a JSON file), and we want a Notification to tell us the progress.

The author of the Notification could be ActivityA, so we can keep on using the App, and even click “back”, and we will still be informed about the progress of our operation.

Well, just one detail when doing that: Don’t forget to set the Notification’s Small Icon, or else it won’t show up (It will if we launch it from ActivityB without smallIcon, but in case of ActivityA, it won’t). Here is some code:

Intent i = getIntent();
int notificationId = 100;
PendingIntent pi = PendingIntent.getActivity(ActivityA.this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
.setContentText("10% parsed")
.setProgress(100, 10, false)
.setSmallIcon(R.drawable.icon); // Do not forget this line!!
mNotifyManager.notify(notificationId, mNotificationBuilder.build());

I know it is quite silly, but remember it! ūüôā

[Android] Eclipse shortcuts i use most

It is worth to spend some time reading about the shortcuts eclipse offers you to save switches / context-changes and become much more productive when coding. One of the most useful tutorials is this one from vogella. After a few years coding, the ones i consider most useful are these: (yellow ones are the best time savers for me)

ctrl+3: quick access to resources
ctrl+2: quick assist – rename/assign tools (renaming vars, assigning operations to local vars)
ctrl+1: quick fix (see my strings resources tutorial)
ctrl+I: automatic code indentation
ctrl+shift+O: fix imports
alt+left: go to previous location
alt+right: go to next location
ctrl+right: move to next text element
ctrl+left: move to previous text element
ctrl+alt+down: clone selected line below (next line)
ctrl+alt+up: clone current line above (previous line)
alt+up: move current line up
alt+down: move current line down
ctrl+D: delete current line
ctrl+DEL: delete next element
ctrl+backspace: delete previous element
shift+enter: adds a new line below current, without deleting or overwriting selection
ctrl+Q: back to the last edited position

And of course, the most traditional and obvious ones:

ctrl+F: find
ctrl+X: cut
ctrl+C: copy
ctrl+V: paste
ctrl+Z: undo
ctrl+Y: redo

I suggest you to correct some bad customs and get used to these shortcuts, and you can focus more on coding and less in interruptions/switches/context changes that often act as obstacles.

Have a nice coding day! ūüôā

Another time-saver! Creating String resources directly from Code editor

Write a string literal in your code like

mButton.setText("Text to add as String resource");

Then select the string literal  like this:


and press ALT+SHIFT+A, a yellow menu will appear in the bottom-right corner,


double click on “Extract Android String” , this menu will appear:


choose a proper name for the String resource and click Ok.

You will get a new strings.xml entry:

   <string name="my_string_resource">Text to add as string resource</string>

And your Button’s setText line replaced by:


Time-saver! creating Android string resources directly from code.

Let’s say you copy and paste an XML TextView:




You probably won’t have the “copy_pasted_string” defined in the strings.xml file, and creating it manually is slow.

On Eclipse, place the mouse over the “copy_pasted_string” text, press CTRL+1 then click “Rename Android resource”.

It will create a new strings.xml entry, plus a new R.string resource in the R.java file.

Saved me thousands of seconds of routinary work!


OsmDroid + Mobile Atlas Creator tutorial

As you may know, Mobile Atlas Creator (from now on, MOBAC) was blocked due to producing high stress on OSM servers, since mid-2013.

So MOBAC can’t generate Mapnik tiles now, and most of the OsmDroid Apps use Mapnik.

What we’re gonna do in this tutorial is to use MapQuest tiles, the ones that MOBAC actually support, instead of Mapnik tiles.


Select “Atlas > New Atlas”

Select the “OSMDroid ZIP” option

Now on the atlas, select “Map Source: OpenStreetMaps mapquest”


Mark the “Recreate/adjust map tiles (CPU intensive)” checkbox


Choose “Tile format: PNG”. To make sure this is correctly done, select another one (like JPEG) and then switch back to PNG.

Drag the area you wish to select and mark the Zoom Levels you want to include in your atlas


Click on atlas name (mine is “Unnamed atlas”), then click on Add Selection. A new layer must be created.


Then on the upper menu, click Atlas > Create atlas

Now you’ll find a .zip file inside your MOBAC folder. Extract it into a temporary folder.

Rename the “MapQuest” folder inside the zip to “MapquestOSM”, and zip it again (pay attention to the caps). Don’t worry about the name of the zip. “MapquestOSM.zip” would be OK, but its not strictly necessary.

copy the new zip file to /sdcard/osmdroid/ (not inside /sdcard/osmdroid/tiles!, just osmdroid folder)

Android code to load the atlas:

public class MyMapActivityBasic extends Activity
  protected void onCreate(Bundle savedInstanceState) {
   MapView mapView = new MapView(this, 256); //constructor
   setContentView(mapView); //displaying the MapView
   mapView.getController().setZoom(15); //set initial zoom-level, depends on your need
   mapView.getController().setCenter(new GeoPoint(mLat, mLon));


When installing Apps in my Android phone using ADB (via Eclipse internally, or via command line tool), i’ve found the following error:

1914 KB/s (4580896 bytes in 2.337s)
pkg: /data/local/tmp/package.apk


It seems to appear mostly on rooted phones (mine is). The solution is to change permissions to directory


from rwxrwxr– to rwxrwxrwx.

This should do the trick ūüôā at least i’m able to install APK’s from now on.

Hope it helps!