Android – Newbie Gotchas

So I was doing this tutorial to make a simple music player in Android, and came across lots of problems, cause they are using SDK version M3, while I’m using SDK version 1.1. Lots have been changed since then….

1. Signature for Notification has been changed. It used to be:

Notification(Context, int, CharSequence, long, CharSequence, CharSequence, Intent, int, CharSequence, Intent)

and now it’s:

Notification(int, CharSequence, long)

2. There is no “-useaudio” option when u run Android emulator using SDK ver1.1. Your application will still run without this option.

3. “class” has been substitute with “android:name” when you are writting your android.manifest file. It used to be:

<service class=".MDService" android:process=":remote" />

and now it’s:

<service android:name=".MDService" android:process=":remote" />

4. When you write your layout XML, remember that “id” needs to be changed to “android:id”. It used to be:

<ListView id="@id/android:list"/>

and now it’s:

<ListView android:id="@id/android:list" />

5. You need to catch or throw RemoteException when calling a Service object.

6. Whenever you call a Notification object, you always need to .setLatestEventInfo(), otherwise you will get an IllegalArgumentException during runtime.

Notification notification = new Notification(R.drawable.playbackstart, file, System.currentTimeMillis());
ComponentName comp = new ComponentName(this.getPackageName(), getClass().getName());
Intent intent = new Intent().setComponent(comp);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(this, "Title", "Text", pendingIntent);
nm.notify(NOTIFY_ID, notification);


Related links:
Id on ListView
Notification and setLatestEventInfo