Pav*_*vel 10 android widget android-jobscheduler
我们的应用程序中有一个时钟小部件.小部件需要每分钟更新一次以显示正确的时间.
在Android O中,建议使用JobScheduler进行后台更新.不幸的是,存在局限性.
在O之前,我们曾经使用Handler.postDelayed()运行后台服务来更新小部件中的时间.在O中,后台服务可以由系统终止.
您如何推荐在Android O中实现时钟小部件?
这现在有可能吗?
使用"TextClock"小部件控件,它受RemoteView功能支持,它每分钟都自动更新,无需使用那些花哨的JobScheduler作业.
像这样的东西可以解决这个问题:
<LinearLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextClock
android:id="@+id/dateText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:format12Hour="@string/date_text_format_12h"
android:format24Hour="@string/date_text_format_24h"
android:gravity="bottom|center_horizontal"
android:textColor="@android:color/black"
android:textSize="@dimen/date_text_size_default"/>
<TextClock
android:id="@+id/timeText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:format12Hour="@string/time_text_format_12h"
android:format24Hour="@string/time_text_format_24h"
android:gravity="top|center_horizontal"
android:textColor="@android:color/black"
android:textSize="@dimen/time_text_size_default"
android:textStyle="bold"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1086 次 |
| 最近记录: |