似乎NotificationManager 的 API 参考有点混乱。
这是通过Google Code Search 在 NotificationManager 和 Android 上找到的代码:
/**
* 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
。
关于按值传递和按引用传递的一般问题,简单/粗俗的解释是:
有关说明,请参阅 arnivan 和 Patrick 的评论。