我有1个活动和1个普通类,其中一个活动接收消息,普通类发送消息。如何实现它:
在 ActivityOne.class
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public mHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 10:
Toast("Get message 10");
break;
case 1:
Toast("Get message 1");
break;
}
}
};
}
public void Toast(String text) {
Toast.makeText(ActivityOne.this, text, Toast.LENGTH_SHORT).show();
}
在 Ordinary.class
如何编码 sendEmptyMessage(1) ?