advanced

Debugging database

SDK Version: 
M3

When I first tried to manage an sqlite database on an android device I was not sure about where I fail in it. Can I even insert the records into the database, or I fail only to read the data from it? So I started to search for possibilities to debug the database lifecycle.

The system stores databases in the /data/data/package_name/databases folder by default.

In a command line using the adb (Android Debug Bridge - found in the android sdk tools library) you can access the databases on a running emulator like below:

  1. adb -s emulator-5554 shell
  2.  
  3. sqlite3 /data/data/package_name/databases/database_name

After this you can type normal SQL commands to test the content. For example:

  1. SELECT * FROM table_name;

This will list the table content (in an ugly format), or say that it does not exists.

Days to Xmas widget tutorial

SDK Version: 
M3

My second article based on Norbert Möhring's HelloWidget tutorial, but i think it's easier. :) It will look like this:


xmas widget

How to disable a button on an appwidget?

SDK Version: 
M3

Would you like to disable a button on an appwidget?
As far as I know it can not be done, since the appwiget UI manipulation is limited by the methods of the RemoteViews class.

But if you insist to do that there is a way to make it look like the button were disabled!

RemoteViews can't manipulate a buttons enabled/disabled state, but it can modify its visibility. So the trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.

Lets see a simple example:
We want to have two buttons on the widget, a stop and a start button in order to stop and start some kind of functionality. Once we have started it, we can not start it agin, until we stopped it and vica versa, so we want to disable the button which can not be used right now.

The XML definition of the buttons can be like this:

  1. <Button android:id="@+id/startbutton" android:text="Start" android:visibility="visible" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
  2. <Button android:id="@+id/startbutton_disabled" android:text="Start" android:clickable="false" android:textColor="#999999" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

How to debug a Service?

SDK Version: 
M3

In this tutorial we will show you how you can easily debug a service.


debugIntroduction

When you start a project with a service in it in debug mode, and you placed a breakpoint in a method of the service, the debugger will not stop. 

Solution

The solution that works in almost all situation is to wait declaratively in the code for the debugger to attach. To do this, you have to make a call to:

  1. android.os.Debug.waitForDebugger();

The breakpoint can be inserted at any line after this call. 

As a complete example, the SoftKeyboard tutorial is enhanced with the call above:

  1. public class SoftKeyboard extends InputMethodService
  2.         implements KeyboardView.OnKeyboardActionListener {
  3.        
  4.     @Override
  5.         public void onConfigurationChanged(Configuration newConfig) {

TourGuide - Virtual Sightseeing

SDK Version: 
M5

This tutorial creates a MapActivity which has a spinner floating above a MapView. You can select different locations from the spinner and hit the button to view that location. The locations are a handful of the "Most Popular Destinations" from http://www.satellite-sightseer.com/

PhoneFinder - SMS Phone Locator

SDK Version: 
M5

In this tutorial we will create a GPS Phone Recovery application. The application will allow the user to setup a password that he or she can use to recover a lost or stolen phone. Once the user has setup the password, if they lose their phone they'll be able to send a text message to their phone from another cell phone and if the text message is formatted "SMSLOCATE:[password]" with the correct password then the phone will respond with all of the data about the phone's current location from the GPS. This includes latitude, longitude, altitude, heading, speed, and more.

MusicDroid - Audio Player Part II

SDK Version: 
M3

In part 2 of the MusicDroid media player tutorial series, we will move the MediaPlayer object into a remote service so that you can use the rest of the phone while playing your music. We will setup this service so that it will be simple to add the controls in part 3 for Pause, Stop, Skip forward, Skip back, etc. This service will also provide a marquee notification each time a new song starts, and a notification icon for play/pause status.

MusicDroid - Audio Player Part I

SDK Version: 
M3

In part 1 of this 4 part series, we will setup a very basic music player that will list all songs on the SD card and allow the user to select a song to play. Over the course of this series we will build a fully functional MP3 player with animated controls and IDE3 tag support.

NewsDroid RSS Reader

SDK Version: 
M3

In Hello Android's first tutorial we will walk through creating a simple RSS reader. This tutorial will show you how to parse XML files and use the SQLiteDatabase for storage.

Syndicate content