NotificationManagerのAPI リファレンスが少し混乱しているようです。
NotificationManager および Android で Google Code Search を介して見つかったコードは次のとおりです。
/**
* Persistent notification on the status bar,
*
* @param tag An string identifier for this notification unique within your
* application.
* @param notification A {@link Notification} object describing how to
* notify the user, other than the view you're providing. Must not be null.
* @return the id of the notification that is associated with the string identifier that
* can be used to cancel the notification
*/
public void notify(String tag, int id, Notification notification)
{
int[] idOut = new int[1];
INotificationManager service = getService();
String pkg = mContext.getPackageName();
if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")");
try {
service.enqueueNotificationWithTag(pkg, tag, id, notification, idOut);
if (id != idOut[0]) {
Log.w(TAG, "notify: id corrupted: sent " + id + ", got back " + idOut[0]);
}
} catch (RemoteException e) {
}
}
明らかに、パラメーターは値を返しません。彼らは同様の JavaDoc を持つつもりでしたが、おそらく間違いを犯しました。
の他のバリアントのコードを見てくださいnotify
。
/**
* Persistent notification on the status bar,
*
* @param id An identifier for this notification unique within your
* application.
* @param notification A {@link Notification} object describing how to
* notify the user, other than the view you're providing. Must not be null.
*/
public void notify(int id, Notification notification)
{
notify(null, id, notification);
}
ご覧のとおり、このオーバーロードされたバージョンは、デフォルトのtag
String 値であるプライマリ実装を呼び出すだけですnull
。
値渡しと参照渡しの一般的な質問に関して、単純/下品な説明は次のとおりです。
- Java はプリミティブを値で渡します。
- ただし、参照によってオブジェクトを渡します。
明確にするために、arnivan と Patrick によるコメントを参照してください。