Chinaunix

标题: framework中使用toast显示信息 [打印本页]

作者: 电子学习员    时间: 2015-07-16 14:43
标题: framework中使用toast显示信息
平台:android5.0

需求:framework中添加一个系统服务,服务中接收字符串,用toast显示。


实现:
1。实现一个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为多用户,使用该方法实现后,在owner用户下可以吐司,但切到其他用户下不能吐司,现在分析不出原因出在哪里,希望大侠能指点以下,谢谢!


作者: 电子学习员    时间: 2015-07-16 14:44
自顶,等大侠。。。。。
作者: xiaoliaozi    时间: 2015-07-20 15:27
顶帖,等大神出来解决。。。
作者: 电子学习员    时间: 2015-07-28 14:08
大神在哪里。。。
作者: renxiao2003    时间: 2015-08-12 10:51
支持。现在做的是4.x的开发。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2