Debugging Android Project DDMS Heap Dump in Eclipse

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

First off, what is a heap dump? A heap dump is essentially a snapshot of an application’s data at a given point in time.  It maps a specific process, view, etc. to the memory being used.  Sort of like ctl-alt-delete on windows in order to determine what’s using up your app’s memory.

To get a heap dump in Eclipse for an application running on your device:

  1. Open Eclipse
  2. Run the target application on the target device by pushing the application to the device over USB (then keep USB connected).
  3. Select Window->Open Perspective->DDMS
  4. The target device should be shown on the left side in the devices window.
  5. The target application should be shown under the device
  6. Select the target application and then the Dump HPROF file icon(half-full glass with green fluid and red arrow). This will prompt you to save the file; do so.

Convert Android HPROF to readable HPROF

  1. The previous file cannot yet be read by the Eclipse MAT tool (see below) and so must be converted first.
  2. On your computer go to C:\…\android-sdks\tools (where … is wherever you installed eclipse) and copy the hprof-conv.exe file
  3. Navigate to the folder where you saved the heap dump and paste the hprof-conv.exe file (you can probably keep it in its original location and navigate to files, but I’m lazy).
  4. Open a command prompt and navigate to the folder where your file and the hprof-conv.exe file are located (can do using cd:\folderName).
  5. Type the following line into the command prompt and hit enter:

hprof-conv dump.hprof converted-dump.hprof

Your newly converted file will be created in the same folder as the original file and will be called converted-dump.hprof.

Opening HPROF in Eclipse after conversion:

  1. Go to Window->Open Perspective->Other->Memory Analysis
  2. This may take a while to open
  3. When it opens, it will show up amoung the coding windows-at least mine did-and so find it using the window icon that looks like a disk structure
  4. From here, you will be at the home screen of MAT with your app’s dump file.  Use any of the following links as reference on how to analyze things:

NOTE: READ THIS…I was trying to open the converted file in Eclipse since I had the MAT plug-in installed and everything went well.  But, that was only because I recorded the HPROF before installing the MAT plug-in for Eclipse.  After I installed that plug-in, DDMS stopped asking me where to store my file and what to name it.  This became very frustrating since I couldn’t get dump files, but I noticed that randomly numbered tabs were showing up in the java perspective and had the MAT disk icons.  Well…blam! Those were the dumps and already converted for me.  Also, if I hit the phone icon in DDMS it will do a screen capture dump showing me layout views and images on screen! Awesome!!!!

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

Eclipse GitHub Push Error: master:master [rejected – non-fast-forward]

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

So, you’ve run into the following VERY annoying message:

master:master [rejected – non-fast-forward]

If you are a nube to Git, which I certainly am, you have no clue what this means, why it’s happening, or how to fix it.  Also, if you’ve traveled down the same path I have, then you’ve encountered this message after one of the following scenarios:

  1. Used EGit in Eclipse to connect a local repository to an already created repository on GitHub.  After setting correct SSH and then trying to push, you get said message.
  2. Local repository has been pushing to remote repository on GitHub forever and randomly crapped out with the message.

If so, then the problem is most likely that your local and remote repositories are out of sync, and there’s a conflict between some files.  Follow the procedure below to resolve this problem.

  1. First, make sure the most recent changes have been committed. To do this, in Eclipse, right-click on the application’s folder->Team->Commit.  If a pop-up does not say “Up-to-date”, then finish committing the current changes to the local repository.  If it’s already up-to-date, continue.
  2. Try to pull from the remote repository to the local repository; then push to it. To do this, in Eclipse, right-click on the application’s folder->Team->Fetch From Upstream.  If you were able to pull, then push by right-click on the application’s folder->Team->Fetch From Upstream. If unable to pull because of an error, then continue.
  3. At this point, I had to force a push from my local repository to remote repository on Github.  Forcing a push will override any changes on Github with the changes from your local repository! If this is not your goal, DON’T CONTINUE. If it is your goal then do the following:
  • Right-click on application’s Folder->Team->Remote->Configure Push To Upstream
  • Configuration dialog will pop-up->Under “Ref mapping” hit “Advanced” button
  • Push Ref Specifications will pop-up->Select “master [branch]” under “Source Ref” and “Destination Ref”
  • In same window select “add spec”
  • You should now see this update in the “Specifications for push” window; select “Force Push” next to it
  • Select “Finish”

At this point my problem was fixed, but I also didn’t care about throwing  away changes on GitHub.  If you are concerned about this, please keep Googleing because I don’t know how to fix it.

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

Connect Eclipse Repository to GitHub using EGit

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

I assume that if you’re reading this, you know something about the content/document management system called git. Hopefully you understand what a repository is and how to push from a local repository to a remote one, and then pull from the remote repository to the local one.  If not, read about git here.

Also, I’m assuming that you know what Eclipse is and have installed Egit.  If not, read the EGit installation tutorial here.

So, you know what git is and have used EGit a little, but what is Github? Github is a website that allows its users to create remote repositories that are shared with everybody on GitHub – unless the user purchases a private repository.  Users who are added as collaborators can pull the code from the remote repository on Github to a local repository on their machine, modify it, and then push the updated code back to the repository on Github.  Non-collaborators cannot push changes but they can pull code to a local repository on their own machine and use it as they wish.

The following procedure explains how to use Egit from within Eclipse to create a repository on your local machine for storing and managing an application’s files and their history.  It then explains how to connect the local repository to a remote repository on Github so that other users can access it.  This procedure is the same as described in this YouTube video, but clarifies some confusing steps that are essential to this working.

1. Open Eclipse

2. Create  the “Hello World!” application as explained here.

3. Right-click on the “Hello World” folder in the Package Explorer Window

4. Select Team->Share Project


5. In the pop-up window select “Git” then “Next”


6. In the Configure Git Repository window select “Create” next to the Repository dropdown menu.


7. In the Create a New Git Repository window type the parent directory and the name of the folder you’d like.  Both of these are the user’s choice. Select Finish


8. Select “Finish” in the Configure Git Repository window to create the repository in the selected folder.  This will delete the project from the workspace folder and put all of the files in the new repository.


9. There will be a red exclamation mark over the “Hello World” folder in Eclipse with the note [Hello World NO-HEAD].  This is because the repository is empty until the first commit.  To commit the project files to the repository for the first time.  So, commit the files for the first time by right-clicking on the application’s folder->select Team->Commit.


10.  In the Commit Pop-up window say “First commit” (or whatever you want) and select all files-my personal preference but you can select what files to commit.


11. There may still be a problem.  If so, right-click on the application’s folder and select “Close Project”.


12. Reopen the project by right-clicking on the application’s project and selecting “Open Project”.

13. Select Project in the Eclipse menu, then “Clean Project”.  Select the application’s folder and hit “OK”.  The errors should be gone.


14. The project is now using the local repository to store its files and is able to track changes-though the user must commit in order for changes to be saved to the repository.

15. In order to synchronize the local repository to Github, you need to generate an SSH key. In the Eclipse menu select Window->Preferences->General->Network Connections->SSH2.  Then select the “Key Management” tab and click the “Generate DSA Key”.  This will populate a key in the window below the buttons.  If you can’t see it, expand the window-mine was gone until I maximized the window.  Copy this key into the clipboard.  Select “Save Private Key”, select the destination folder (I used the default folder) and select “OK”.




16. Go to and sign into your account.  If you have not created an account, do so now.

17. Select the “Add New Repository” button at the top right of the screen.

18. Type in “Hello World” as the new repository name and make it “Public”-unless you would like to pay for it, then you can make it private. Then select “Create Repository”.


19. The new repository has been created and the path for it is listed under the header “Quick Setup.”  Select the “copy to clipboard” icon to the right of the repository path name-and don’t copy anything else to the clipboard!


20. Go back to Eclipse and open the Repository Browser by selecting Window->Show View ->Git Repositories


21. In the Repository Browser expand “Hello World”, right-click on “Remotes”, and select “Create Remote”.


22. Call your new remote “origin”, select “Configure Push” and hit “OK”.


23. In the “Configure Push Window” select “Change” under URI.  This will open the “Destination Git Repository” window.


24. In this window you should automatically see the new repository information populated.  If not, it’s because you copied something else to your clipboard, so close the window and copy the repository link from Github again. Select “SSH” under “Protocol” and select “OK”.


25. The “Hello World” app should now be pushed to Github and you should be connected.

NOTE: If the pushed failed due to:

master:master [rejected – non-fast-forward]

Then see my post on fixing this issue.

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

Creating a new Android project in Eclipse (hello world)

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

Before starting this tutorial, you should have read, understood, and successfully completed the tutorials listed below.  These tutorials are the building blocks for this tutorial and are listed in order from basic building blocks to compound ideas.

  1. Installing Eclipse-TODO
  2. Updating Eclipse-TODO
  3. Importing Libraries into Eclipse-TODO
  4. Linking libraries to projects in eclipse-TODO

Having completed these tutorials, you can now move on to creating a new Android project that will simply display “hello world!” on the device screen.

To do this, follow the procedure below:

1. Open Eclipse and let it load workspace.

2. Click File->New->Android Application Project


3. Enter the application, project, and package name as shown in the image below.


4. Configure the project as shown below.


5. Configure the attributes of the icons as shown below.


6. Create a blank activity as shown below.


7. Create the main layout for the activity as shown below and select “Finish”.


8. The application will be created and the main xml layout file will automatically be displayed as shown in the image below.


9. To run this application on your device right-click on the Example_helloWorld folder in the Package Explorer window on the left hand of the screen.  Then select Run As->Android Application Project as shown below.


10. If your device is connected, it will be shown in the Android Device Chooser window.  Select your device and select “OK”.  Eclipse will compile the code into an Android Package file (.apk) and transfer it to your device.


11. Your device’s screen should be white and say “Hello world!”.

That’s it! Your first Android application is completed.

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

Android Horizontal and Vertical GridView Tutorial

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!

This tutorial demonstrates how to install Jess Anders’ two-way-gridview library in Eclipse along with my test application that uses the library for a horizontally scrolling gridview and a vertically scrolling gridview.  The horizontally scrolling GridView covers the top third of the screen with a vertically scrolling GridView covering the bottom two thirds of the screen (as shown in the images below).  The number of columns and rows changes based on orientation in order to demonstrate the ease in which the two-way-GridView can change orientation.  Also, notice that the vertically scrolling GridView looks exactly like a ListView but still uses the adapted GridView code.


Each GridView is populated with a very simple Custom Adapter that extends the BaseAdapter class.  The list that is passed to the adapter consists of very simple objects which hold a string and an int; the string is the item’s name (Item i) and the int is a randomly generated color.  These objects could hold images, but a different adapter class is required for better performance and intelligent memory usage.

Installing the library and test application

1. Download the two-way-gridview library from GitHub and unzip the download into its own folder.

2. Open Eclipse and select File->New->Other

3. Select “Android Project From Existing Code” and select “Next”

4. Select “Browse” and navigate to the extracted folder from step 1. Hit “OK”.

5. You should see the following screen showing that one library project and one sample project will we imported:

HorizontalVerticalGridview example

6. Select “Finish” and both projects will be imported. There may be errors at this point.  The first error was in the folder “MainActivity”, but it went away after the project was completely built.  The other problem could be a broken link in the “MainActivity” to the library.  If so, right-click on the MainActivity folder, select Properties->Android->Scroll to bottom of  the screen until “Library” is seen->Add the library->and point to the lib.  Finally, one last issue could be that the entire folder was imported using File->Import.  This will import one folder with two projects.  If this was the case, remove that project and repeat the above steps.

7. With the library installed, download the Horizontal and Vertical Gridview Example code from GitHub.

8. Import the project using the method previously described.

9. When the project has been imported there will be an error because the library is missing.  If so, right-click on the Example_horzAndVertGridViews folder, select Properties->Android->Scroll to bottom of  the screen until “Library” is seen->Add the library->and point to the lib.

10. At this point the example activity should be installed and able to run.

Notes about the application and using the library:Let me start by saying I’m no Android expert and using Jess’s demo to achieve the proper item spacing and dimensions may be the best approach. Regardless, I was not able to use that example to easily set the number of columns and rows for the GridView while creating the desired spacing between items.  This example will hopefully demonstrate that.  The functionality to achieve this is explained by file below.

  • Sets the number of objects for each GridView.
  • Calls generateGridViewObjects() to  instantiate a list of DataObjects.
  • Passes the list to the adapter-one list for each GV and its adapter.
  • Randomly selects a new color for each newly instantiated DataObject and sets its name to “Item i”, where i was it’s order of creation.

  • A very simple object that holds the item name as a String and the item color as an int.

  • Custom adapter that extends BaseAdapter class
  • Uses ViewHolder class for storing view handles to reduce number of times findViewById() is called
  • Uses recycled convertView and doesn’t create new view for each object in the list
  • Gets row and column values from integer-array in integers.xml
  • Gets item padding from dimens.xml
  • Passes row value to setNumRows() and setRowHeight(); setNumColumns() and setColumnWidth() ignored when GV is horizontal, so no reason setting them
  • Padding around item is set in each child’s FrameLayout; see details below
  • Since item height and width are determined by the largest child’s values, this sets the child’s ImageView height and width using layout parameters
  • DO NOT set the child’s FrameLayout layout parameters or the converView’s layout parameters.  Setting either will cause a new view to be created for each object in the list. While these views are eventually reduced down to the number on screen, the initial creation of so many views crashes a simple application. No clue why, it just does.
  • If the child’s TextView is larger than the ImageView, unpredictable spacing between items will occur.  But, DO NOT set the layout parameters of the TextView because that too will force a new view to be created for every object in the list.  Instead, either shorten the text, reduce text size, or have fewer number of columns to fit the larger text.

  • Same as except for the Vertical GridView and the following:
  • Passes column value to setNumColumns() and setColumnWidth(); setNumRows() and setRowHeight() ignored when GV is vertical, so no reason setting them


  • Jess’s example sets many more properties such as number of rows and height, etc.  This example does not because I found it impossible to get the sizing and dimensioning to work correctly using properties in xml and so set all of them programatically in the adapter for each gridview.
  • cacheColorHint and bg should be set to a constant color for improving performance-recommended by Google.
  • Vertical spacing and horizontal spacing seem to be intended for padding, but made it difficult to get the layout to show correctly.  Therefore, these are set to 0 and padding is set in the FrameLayout of the child view.  The child’s padding is also used to determine the ImageView height in the adapter’s getView() function
  • Stretch mode is meant to “properly” space the items on the screen, but again, using any setting but “none” just made life difficult
  • app:scrollDirectionPortrait and app:scrollDirectionLandscape tell the GV what direction to scroll; while the scrolling direction can change based on orientation, I kept it the same direction regardless of orientation


  • Child layout for horzGridView
  • FrameLayout has padding because it just made life easier than setting it elsewhere
  • ImageView controls height and width of every child and is set in adapter’s getView() which overrides the height and width from xml


  • Child layout for vertGridView
  • FrameLayout has padding because it just made life easier than setting it elsewhere
  • ImageView controls height and width of every child and is set in adapter’s getView() which overrides the height and width from xml

values-xxx folders

  • The integers.xml file in each of these folders specify the number of rows and columns for each GridView.  These values change based on orientation (using the -land folders) and screen size (using sw600dp for 7″ tabs and sw720dp for 10″ tabs).

In a future tutorial I will show how to apply drag and drop to these gridviews.

Helpful? Then DOWNLOAD and RATE my app!

Helpful? Then DOWNLOAD and RATE my app!