在 BitmapFactory.decodeStream 方法中:
public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts) {
// we don't throw in this case, thus allowing the caller to only check
// the cache, and not force the image to be decoded.
if (is == null) {
return null;
}
Bitmap bm = null;
Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
try {
if (is instanceof AssetManager.AssetInputStream) {
final int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
bm = nativeDecodeAsset(asset, outPadding, opts);
} else {
bm = decodeStreamInternal(is, outPadding, opts);
}
if (bm == null && opts != null && opts.inBitmap != null) {
throw new IllegalArgumentException("Problem decoding into existing bitmap");
}
setDensityFromOptions(bm, opts);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); // THAT IS COLLISION LINE
}
return bm;
}
我们看到了使用情况Trace.TRACE_TAG_GRAPHICS
。好的,让我们看一下 Trace.java :
public final class Trace {
/*
* Writes trace events to the kernel trace buffer. These trace events can be
* collected using the "atrace" program for offline analysis.
*/
private static final String TAG = "Trace";
// These tags must be kept in sync with system/core/include/cutils/trace.h.
/** @hide */
public static final long TRACE_TAG_NEVER = 0;
/** @hide */
public static final long TRACE_TAG_ALWAYS = 1L << 0;
/** @hide */
public static final long TRACE_TAG_GRAPHICS = 1L << 1;
...
当我尝试使用Trace.TRACE_TAG_GRAPHICS
标志编译器时,给我错误,这个标签不对我负责。我同意他的看法。
但问题是 - 为什么 BitmapFactory 可以访问@hide
个变量以及为什么我没有?
答案 0 :(得分:0)
对于私有 API,它们不是已发布的官方Android API的一部分,Android使用@hide
注释来防止它们被包含在您的程序编译的jar中。我们无法保证将来可以使用这些产品,因此您不应该依赖它们。如果您需要使用它,可以通过Reflection访问它。