1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| static class MyHandler extends Handler { WeakReference<PopupActivity> mActivity; MyHandler(PopupActivity activity) { mActivity = new WeakReference<PopupActivity>(activity); } @Override public void handleMessage(Message msg) { PopupActivity theActivity = mActivity.get(); switch (msg.what) { case 0x0001: theActivity.textView.setText(R.string.hello_world); break; } case 0x0002: theActivity.textView.setText(R.string.welcome); break; } } };
MyHandler testHandler = new MyHandler(this); private void test1() { testHandler.sendEmptyMessage(0x0001); } private void test2() { testHandler.sendEmptyMessage(0x0002); }
|