# ServiceFragment **Repository Path**: blestland/servicefragment ## Basic Information - **Project Name**: ServiceFragment - **Description**: 本库的Service可以直接显示Fragment,从而支持LiveData,支持MVVM。 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: https://gitee.com/blestland/servicefragment - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-01-01 - **Last Updated**: 2022-02-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README **源起** 本项目是一个开源库,设计本库的源起是希望在Service中通过addView显示的控件能够遵循MVVM架构和LiveData机制。 Android原生Service可以通过addView的方式来直接显示一个控件,从而可以支持飘浮在所有窗口之上的显示层(术语为Z序)。但是addView只能添加单个View控件,不支持添加Fragment更不支持添加Activity,而我们知道,只有Fragment和Activity才支持LiveData机制的LifecycleOwner。这样一来,原生Service的addView显示机制,就不能支持LiveData机制,也就不能支持MVVM架构了。 **原理** 一个假的Fragment,支持在Service中直接使用,支持LiveData,底层实际上是对addview的封装并增加了对LiveData机制的支持。