Android

Last updated: 03-12-2011, Back

Getting started on a Windows PC (32bit):
  1. First decision: 32 or 64bit development machine (see below).
  2. All information can be found at Android Developer
  3. For installation of the SDK read this page at Android Developer Install
  4. - Install the Java Platform (JDK) from Oracle JDK
  5. - Install Eclipse Classic from Eclipse Org
  6. - Install Android SDK from Android Developer SDK
    Don't install the Android SDK in "C:\Program Files\Android\....." but install it in "C:\Android\..." otherwise you will get an AVD Run error "Hint: use '@foo' to launch a virtual device named 'foo'." which is caused by the space character in the SDK path ("Program Files"). You may have to disable your AntiVirus program (I had to disable Norton's) for the installation of updates of the packages (and updating takes time...).
    Then you have to set up an Android Virtual Device (AVD) which is an emulated Android cellphone.
  7. Helpfull source www.stackoverflow.com
[Development] 32bit or 64bit
  1. If you want to use Samsung sensor sdk then you have to use 32bit Windows (XP, Vista, 7) or MacOs and Eclipe 3.5 or 3.6.n .
  2. 32bit Windows/Linux: everything works (except on Linux the Samsung sensor sdk).
  3. 64bit Windows7: Install a 32bit Eclipse and JDK. This is a NO-GO area when you need sensor simulation (Samsung sensor sdk crashes).
  4. 64bit Linux: Requires a lot of time to get it working (32bit libs needed).

[Development] Cloning an Android Project in Eclipse

    Assume you have a WorkSpace at "D:\workspace" and want to clone an existing Android project named "B".

  1. Windows: go to the WorkSpace
  2. Windows: make a copy of the complete project directory named "B" (Windows makes a "B - Copy")
  3. Windows: rename the copied directory "B - copy" into the clones name, in this case: "B_00"
  4. Windows: Go into directory "B_00" and edit file ".project"
    Change the line with "<name>B</name>" into "<name>B_00</name>"
    Windows: save the file
  5. Start Eclipse and open it in your WorkSpace. "B_00" is not visible.
  6. Eclipse: Menu File -> Import
    Eclipse Import dialog Select: select General -> Existing Projects into Workspace
    Eclipse Import dialog Select: push button "Next"
    Eclipse Import dialog Import Projects: select "select root directory" and then "Browse..." to "B_00"
    Eclipse Import dialog Import Projects: push button Finish.
  7. Eclipse: package explorer: select "B_00"
    Eclipse: Menu Project -> Clean...
  8. Done.

[Android] ActivityNotFoundException on "MyActivity"
Check the AndroidManifest.xml file there should be a line for each activity like this :
<activity android:name=".MyActivity" />

[Android] NullPointerException reported via Android Market
Make sure you initialize (new) all data when declared. Even if you use a splashscreen to initialize/read data/parse xml/etc so there can not be a reason for a NullPointerException. With the AVD or your phone these errors are often not reproducable but your app users have them. When destroying data don't null them but use new (and make sure your app can handle that). The reason for all this is that activities start/stop differently in the outside world then they do with the AVD or on your phone.

[Android] Messages, Intents, static class and application data
On the internet intents are often described as messages which you can use to pass data from one activity to the another activity. Well you can pass data with them but only the sending activity creates a new destination activity. Thus you can not exchange data between already existing/running activities.
If you want to pass data between active activities one way is to use a "static class" and beter add a "destroy" methode to clean up (see NullPointerException) the data when the program exits because a static class exists as long as the DVM is running.
I did found a better way to pass data between activities, see this link. Basically give your application a name (MyApp) in AndroidManifest.xml, create a class MyApp which implements android.app.Application, use the singleton pattern for this class and put all your global data/get/set methods in. In each activity's create use "MyApp aa = getApplicationContext()" and access all data/get/set methods via "aa.".

[Android] ColorPicker
The AmbilWarnaDialog color picker is nice but adds about 20 kb to your Android app and that is a lot. I found another one at yougli which adds only about 4 kb but it needs some rework to fit it in 200*200 or 400*400 pixel dialog, or to scale it properly for larger resolution screens. [Android] ddms
You will find it in android-sdk/tools. Connect the USB cable to your phone + computer. Set your phone in the develloper mode. Now you can take screenshots (check ddms menu's) from your phone while running any app. And there is more...

[Android] Orientation verses magnetometer/accelerometer
Orientation delivers data in degrees: azimuth [0..360.0]; roll [-180.0..180.0]; pitch [-180.0..180.0] . Magnetometer/accelerometer, after getRotationMatrix & getOrientation, delivers data in radians: azimuth [-PI..PI]; roll [-PI..PI]; pitch [-PI/2..PI/2] where roll, pitch and azimuth are somehow connected. When adding pitch up to -90 degrees the azimuth then flips (example: 10 to -170) aswell as the roll (example: 0 to -180) and adding more pitch (> 90 degrees) decreases the pitch (in radians).

[Android] Simulating sensors: Samsung Sensor SDK verses OpenIntents.org
Samsung Sensor SDK adds an AVD to the Android SDK and a plugin to Eclipse (only versions 3.5 and 3.6.n !!). All is installed automatically, works and no code change or library is needed to use Samsungs simulated sensors !! The look and feel is good. Just remember to use the added SNR AVD when testing the sensors.
OpenIntents.org.... you have to change your code and add a library to use their simulated sensors, has a simulator application outside Eclipse with a less good look and feel, requires to install an app in the AVD and your app crashes (no response) when you switch between activities.

[Android] Camera preview:
If you want to use the phones camera as a preview in your app then you are in for supprices. It may all work with your Samsung but crashes with HTC or Motorola. This is due to unsupported window sizes, especially when your window (width, height) does not match a multiple of 8 or does not equals the cameras preview sizes (HTC/Motorola). If you don't want to exclude phones pre Android 2.1 you have to do some programming to get it working. The answer can be found at stackoverflow.com or mail me for the preview package.

[Android] Testing, Crash avalanche on the Android Market
Although you have tested your app on your Android phone and tested with various AVD's your app will get error reports about crashes/freezes at code lines where you do not expect them. With the AVD's and your phone it all works fine but every phone manufactor adapts/customizes Android to what they need and they do that for each phone model they make.
Make sure you test your app thoroughly and beyond that. Ask you mother or little sister/brother or any digitally literate to use your app.
After you have released/activated your app to/on the Android market monitor for crashes and freezes reported back from users. Make sure that in the first week you check your market account every 12 houres or so and repair immediatly the reported exceptions and release/activate the update on the market. The first week I made about 5 releases. This will prevent a bad judgement. Read the comments because some users make good suggestions for improvements.

How do I connect the Sony Tablet™ device with adb protocol through USB ?
Windows 7, Windows Vista and Windows XP -
- Install the Google Android SDK and USB driver as described at the following Google Android SDK sites:
- Installing the Google Android SDK - http://developer.android.com/sdk/installing.html
Google USB Driver - http://developer.android.com/sdk/win-usb.html

Once the Google Android SDK and Google USB Driver are installed, open the android_winsub.inf file and copy the the following descriptions into the [Google.NTx86] and [Google.NTamd64] sections of the extras\google\usb_driver\android_winusb.inf file:
;SONY Sony Tablet P
%CompositeAdbInterface% = USB_Install, USB\VID_054C&PID_04D2&MI_01
;SONY Sony Tablet S
%CompositeAdbInterface% = USB_Install, USB\VID_054C&PID_05B4&MI_01

Open a command prompt and enter the following command: echo 0x54c >> %HOMEPATH%\.android\adb_usb.ini
Done. ( Source: http://esupport.sony.com/US/perl/support-info.pl?info_id=878 )

    Recommended Android Market app's:
  1. AndroSensor & AndroSensor Log Collector
  2. ES File Explorer
Back