- 論壇徽章:
- 1
|
平臺:android5.0
需求:framework中添加一個系統(tǒng)服務,服務中接收字符串,用toast顯示。
實現(xiàn):
1。實現(xiàn)一個handler子類,并實例化一個對象
class AvcLogHandler extends Handler {
。
。
。
。
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW_TOAST:
showToast(msg);
break;
。
。
。
。
}
}
public void showToast(Message msg) {
Application application = ActivityThread.currentApplication();
String result = (String)msg.obj;
Toast.makeText(application.getApplicationContext(), result, Toast.LENGTH_SHORT).show();
}
mAvcLogHandler = new AvcLogHandler(Looper.getMainLooper());
。
。
。
。
while(true) {
Message msg = mAvcLogHandler.obtainMessage(SHOW_TOAST);
msg.obj = new String(buf);
mAvcLogHandler.sendMessage(msg);
}
問題:
android5.0為多用戶,使用該方法實現(xiàn)后,在owner用戶下可以吐司,但切到其他用戶下不能吐司,現(xiàn)在分析不出原因出在哪里,希望大俠能指點以下,謝謝!
|
|