当我将小部件放在主屏幕上时如何分配它的设置

how can I assign a widget's settings when I put it on the home screen

如何在小部件的开头打开 Activity 以设置所需的设置?

这个想法是在主屏幕上放置一个小部件,以便能够通过索引定义哪个,即工作数据库。

要在将小部件放在屏幕上后立即启动一些 activity,使用此 intent-filter 在清单中定义就足够了:

<activity android:name=".ConfigurationActivity">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
    </intent-filter>
</activity>

然后在 AppWidgetProviderInfo 元数据中添加 android:configure 条目:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:configure=".ConfigurationActivity"
    android:initialLayout="@layout/widget_layout"
    android:minHeight="50dp"
    android:minWidth="50dp"
    android:updatePeriodMillis="50000" />