下面列出了android.os.Message#recycle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressLint("NewApi")
AsyncHandler(Looper looper) {
super(looper);
if (Build.VERSION.SDK_INT < 16) {
async = false;
} else if (async && Build.VERSION.SDK_INT < 22) {
// Confirm that the method is available on this API level despite being @hide.
Message message = Message.obtain();
try {
message.setAsynchronous(true);
} catch (NoSuchMethodError e) {
async = false;
}
message.recycle();
}
}
private static void recycle(Message m) {
if (recycleUncheckedMethod != null) {
try {
recycleUncheckedMethod.invoke(m);
} catch (IllegalAccessException | IllegalArgumentException | SecurityException e) {
throwIfUnchecked(e);
throw new RuntimeException(e);
} catch (InvocationTargetException ite) {
if (ite.getCause() != null) {
throwIfUnchecked(ite.getCause());
throw new RuntimeException(ite.getCause());
} else {
throw new RuntimeException(ite);
}
}
} else {
m.recycle();
}
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// This is called on the same thread.
mRemoteViewsFactory = IRemoteViewsFactory.Stub.asInterface(service);
enqueueDeferredUnbindServiceMessage();
RemoteViewsAdapter adapter = mAdapter.get();
if (adapter == null) {
return;
}
if (mNotifyDataSetChangedPending) {
mNotifyDataSetChangedPending = false;
Message msg = Message.obtain(this, MSG_NOTIFY_DATA_SET_CHANGED);
handleMessage(msg);
msg.recycle();
} else {
if (!sendNotifyDataSetChange(false)) {
return;
}
// Request meta data so that we have up to date data when calling back to
// the remote adapter callback
adapter.updateTemporaryMetaData(mRemoteViewsFactory);
adapter.mMainHandler.sendEmptyMessage(MSG_MAIN_HANDLER_COMMIT_METADATA);
adapter.mMainHandler.sendEmptyMessage(MSG_MAIN_HANDLER_REMOTE_ADAPTER_CONNECTED);
}
}
void executeOrSendMessage(IInterface target, Message msg) {
if (target.asBinder() instanceof Binder) {
mCaller.sendMessage(msg);
} else {
handleMessage(msg);
msg.recycle();
}
}
private void handleOnUiThread(int what) {
Message msg = Message.obtain(LazyHolder.sHandler, what, this);
if (Looper.myLooper() == msg.getTarget().getLooper()) {
msg.getTarget().handleMessage(msg);
msg.recycle();
} else {
msg.sendToTarget();
}
}
private void handleOnUiThread(int what) {
Message msg = Message.obtain(LazyHolder.sHandler, what, this);
if (Looper.myLooper() == msg.getTarget().getLooper()) {
msg.getTarget().handleMessage(msg);
msg.recycle();
} else {
msg.sendToTarget();
}
}