本文整理了Java中android.os.Message.obtain()
方法的一些代码示例,展示了Message.obtain()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.obtain()
方法的具体详情如下:
包路径:android.os.Message
类名称:Message
方法名:obtain
暂无
代码示例来源:origin: android-hacker/VirtualXposed
private void sendMessage(int what, Object obj) {
Message msg = Message.obtain();
msg.what = what;
msg.obj = obj;
mH.sendMessage(msg);
}
代码示例来源:origin: Justson/AgentWeb
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null) {
callback.handleMessage(Message.obtain(null, -1));
}
}
})//
代码示例来源:origin: Justson/AgentWeb
@Override
public void onClick(DialogInterface dialog, int which) {
if (callback != null) {
callback.handleMessage(Message.obtain(null, 1));
}
}
})
代码示例来源:origin: Justson/AgentWeb
void call(String value) {
if (this.callback != null && this.callback.get() != null) {
this.callback.get().handleMessage(Message.obtain(null, "JsChannelCallback".hashCode(), value));
}
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void send(Message message) throws RemoteException {
lastMessageSent = Message.obtain(message);
directlyOn(messenger, Messenger.class).send(message);
}
代码示例来源:origin: robolectric/robolectric
private void recycle_shouldInvokeRealObject(String recycleMethod) {
Handler h = new Handler();
Message msg = Message.obtain(h, 234);
ReflectionHelpers.callInstanceMethod(msg, recycleMethod);
assertThat(msg.what).isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testObtain() throws Exception {
Message m = Message.obtain();
assertThat(m).isNotNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getLastMessageSentShouldWork() throws Exception {
Handler handler = new Handler();
Messenger messenger = new Messenger(handler);
Message msg = Message.obtain(null, 123);
Message originalMessage = Message.obtain(msg);
messenger.send(msg);
assertThat(ShadowMessenger.getLastMessageSent().what).isEqualTo(originalMessage.what);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testObtainWithHandler() throws Exception {
Handler h = new Handler();
Message m = Message.obtain(h);
assertThat(m.getTarget()).isEqualTo(h);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSendToTarget() throws Exception {
ShadowLooper.pauseMainLooper();
Handler h = new Handler();
Message.obtain(h, 123).sendToTarget();
assertThat(h.hasMessages(123)).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetGetNext() {
Message msg = Message.obtain();
Message msg2 = Message.obtain();
ShadowMessage sMsg = shadowOf(msg);
sMsg.setNext(msg2);
assertThat(sMsg.getNext()).isSameAs(msg2);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testObtainWithHandlerWhatAndTwoArgs() throws Exception {
Handler h = new Handler();
int what = 2;
int arg1 = 3;
int arg2 = 5;
Message m = Message.obtain(h, what, arg1, arg2);
assertThat(m.getTarget()).isEqualTo(h);
assertThat(m.what).isEqualTo(what);
assertThat(m.arg1).isEqualTo(arg1);
assertThat(m.arg2).isEqualTo(arg2);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testObtainWithHandlerAndWhat() throws Exception {
Handler h = new Handler();
int what = 10;
Message m = Message.obtain(h, what);
assertThat(m.getTarget()).isEqualTo(h);
assertThat(m.what).isEqualTo(what);
assertThat(m.getTarget()).isEqualTo(h);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reset_shouldEmptyMessagePool() {
Message dummy1 = Message.obtain();
shadowOf(dummy1).recycleUnchecked();
Message dummy2 = Message.obtain();
assertThat(dummy2).named("before resetting").isSameAs(dummy1);
shadowOf(dummy2).recycleUnchecked();
ShadowMessage.reset();
dummy1 = Message.obtain();
assertThat(dummy1).named("after resetting").isNotSameAs(dummy2);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = LOLLIPOP)
public void testIsInUse() {
ShadowLooper.pauseMainLooper();
Handler h = new Handler();
Message msg = Message.obtain(h, 123);
ShadowMessage sMsg = shadowOf(msg);
assertThat(sMsg.isInUse()).isFalse();
msg.sendToTarget();
assertThat(sMsg.isInUse()).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testObtainWithHandlerWhatAndObject() throws Exception {
Handler h = new Handler();
int what = 10;
Object obj = "test";
Message m = Message.obtain(h, what, obj);
assertThat(m.getTarget()).isEqualTo(h);
assertThat(m.what).isEqualTo(what);
assertThat(m.getTarget()).isEqualTo(h);
assertThat(m.obj).isEqualTo(obj);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testObtainWithHandlerWhatTwoArgsAndObj() throws Exception {
Handler h = new Handler();
int what = 2;
int arg1 = 3;
int arg2 = 5;
Object obj = "test";
Message m = Message.obtain(h, what, arg1, arg2, obj);
assertThat(m.getTarget()).isEqualTo(h);
assertThat(m.what).isEqualTo(what);
assertThat(m.arg1).isEqualTo(arg1);
assertThat(m.arg2).isEqualTo(arg2);
assertThat(m.obj).isEqualTo(obj);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void createMessengerWithBinder_getLastMessageSentShouldWork() throws Exception {
Handler handler = new Handler();
Messenger messenger = new Messenger(new Messenger(handler).getBinder());
Message msg = Message.obtain(null, 123);
Message originalMessage = Message.obtain(msg);
messenger.send(msg);
assertThat(ShadowMessenger.getLastMessageSent().what).isEqualTo(originalMessage.what);
}
}
代码示例来源:origin: robolectric/robolectric
private void recycle_shouldRemoveMessageFromScheduler() {
ShadowLooper.pauseMainLooper();
Handler h = new Handler();
Message msg = Message.obtain(h, 234);
msg.sendToTarget();
Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
assertThat(scheduler.size()).named("before recycle").isEqualTo(1);
shadowOf(msg).recycleUnchecked();
assertThat(scheduler.size()).named("after recycle").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testMessengerSend() throws Exception {
Handler handler = new Handler();
Messenger messenger = new Messenger(handler);
ShadowLooper.pauseMainLooper();
Message msg = Message.obtain(null, 123);
messenger.send(msg);
assertThat(handler.hasMessages(123)).isTrue();
Looper looper = Looper.myLooper();
shadowOf(looper).runOneTask();
assertThat(handler.hasMessages(123)).isFalse();
}
内容来源于网络,如有侵权,请联系作者删除!