首页 > 代码库 > android源代码分析 android toast使用具体解释 toast自己定义
android源代码分析 android toast使用具体解释 toast自己定义
在安卓开发过程中。toast使我们常常使用的一个类。当我们须要向用户传达一些信息,可是不须要和用户交互时,该方式就是一种十分恰当的途径。
我们习惯了这样使用toast:Toast.makeText(Context context, String info, int duration).show();该方法是
系统为我们提供的一个方便的创建toast对象的静态方法,其内部依旧是调用toast的相关方法完毕。以下
就从其源代码对该类的实现做一个分析
在toast类中,最重要的用于显示该toast的show方法调用了service.enqueueToast(pkg, tn, mDuration);也就是说
系统为我们维持了一个toast队列,这也是为什么两个toast不会同一时候显示的原因。该方法将一个toast入队,显示则由系统维持显示的时机。
private static INotificationManager sService;
static private INotificationManager getService() {
if (sService != null) {
return sService;
}
sService = INotificationManager.Stub.asInterface(ServiceManager.getService("notification"));
return sService;
}
该服务sService就是系统用于维护toast的服务。
在toast内部又一个静态私有类TN,该类是toast的主要实现,该类完毕了toast视图的创建,等等
fa
android源代码分析 android toast使用具体解释 toast自己定义
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。