窗口小部件配置活动无法启动

时间:2013-12-09 06:36:25

标签: java android widget

据我所知,如果我为widget定义配置活动,onUpdate()方法将不会调用,直到我不配置它。但在我的情况下,我想知道为什么 - 配置活动没有启动,并在放置小部件后更新方法调用。我的应用程序有其他活动,其中一个在应用程序运行时启动,也许这就是原因?这是我的代码:

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.watcom.MobileInformer"
          android:versionCode="2"
          android:versionName="1.01"
        >
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
    <application  android:label="@string/app_name" android:theme="@style/WatcomTheme" android:icon="@drawable/icon">
        <supports-screens android:smallScreens="true"
                          android:normalScreens="true"
                          android:largeScreens="true"
                          android:xlargeScreens="false"/>
        <activity android:name=".AuthorizationActivity"
                  android:label="@string/app_name" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="com.watcom.MobileInformer.UPDATE_WIDGET"/>
            </intent-filter>
        </activity>

        <activity android:launchMode="singleTop" android:name=".WidgetConfigureActivity" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>
        <activity android:name=".ProjectsActivity" android:screenOrientation="portrait"/>

        <receiver
                android:icon="@drawable/icon"
                android:label="Watcom informer"
                android:name=".MyWidgetProvider" >
            <intent-filter >
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            <action android:name="ru.example.android.widget.ACTION_WIDGET_RECEIVER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="com.watcom.MobileInformer.UPDATE_WIDGET"/>
            </intent-filter>

            <meta-data
                    android:name="android.appwidget.provider"
                    android:resource="@xml/widget_provider" />
        </receiver>
    </application>

    <uses-permission xmlns:android="http://schemas.android.com/apk/res/android"
                     android:name="android.permission.INTERNET" />
</manifest> 

widget_provider.xml

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="schemas.android.com/apk/res/android"
                    android:minHeight="320dp"
                    android:minWidth="100dp"
                    android:updatePeriodMillis="1800000"
                    android:initialLayout="@layout/widget_layout"
                    android:configuration="com.watcom.MobileInformer.WidgetConfigureActivity"/>

WidgetConfigureActivity

public class WidgetConfigureActivity extends Activity {
    int widgetId;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setResult(RESULT_CANCELED);
        setContentView(R.layout.login_layout);

        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras!=null)
            widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
        if (widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
            finish();
        }

        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        setResult(RESULT_OK, resultValue);
        finish();
    }

0 个答案:

没有答案