Before an application is uploaded into Google, it must be aligned to the 32bit boundary. The alignment will be checked by the Google during the upload process. If it fails, a pop up message will say that the .apk is not aligned and reject the upload. The zipalign tool is located to /tools. You can call it directly or add it to your PATH environment variable. To execute it, use the following zipalign -v 4 < outfile.apk> The outfile is now ready for upload into Google.
In the side project, I wanted to play a sound that I have embedded as part of the resources. After a short research, Android provides MediaPlayer to help you play sounds and videos. I am only going to use it playback some sounds. Before I started, I browse over to the MediaPlayer docs on Google. The most important is the state diagram that it is displaying. From here, it is required for states of your implementation of the player to follow. To start with, you will need to create your instance of MediaPlayer.
mp.start(); When create() is called, the MediaPlayer enters into Prepared state. This means that we can immediately call the start() and the MediaPlayer transitioned into the Started state. The audio will start to play on the speaker. To stop the playing, stop() can be called. When stop() is called, the MediaPlayer transitioned into Stopped. The audio will stop to play and be silent on the speaker. To playback, instead of calling create() again, it is better to call prepare(). From the state diagram, the MediaPlayer will transition from Stopped to Prepared. A boolean could be used to track if the MediaPlayer has been created or not. This is to indicate whether create() or prepare() should be called.
As I am developing the Android App, I need to add a simple menu for popping up a dialog box to show the version of the application. As far as I know, the only menu that can be popped up is the Menu button. On a phone, this soft button is usually located on the bottom left hand corner. I wanted to have a single menu item in the list. It is simple "About" Firstly, I create a menu.xml and placed it in under /res/menu.
In the snippet of code, I have also shown the code for the action bar. However, the line of the that creates the option menu the call to getMenuInflater(). Be sure that the ID of the xml file is referenced correctly.
When the menu button is clicked, a menu will pop up with only the "About" option displaying.
Thirdly, I created code to handle the event when the "About" option is selected. This is handled in the onOptionsItemSelected() method. So I have the following implementation.