【问题标题】:Launcher activity instance restarts when widget configuration activity closes小部件配置活动关闭时启动器活动实例重新启动
【发布时间】:2012-08-11 01:12:55
【问题描述】:

我有一个可用于配置小部件的活动 A。但也可以直接从启动器启动。保存小部件配置实例时,启动器实例会重新启动。我想知道为什么。

首先,我从启动器启动活动。然后我按下 Home 按钮以停止活动。

现在我单击主屏幕上的小部件,小部件配置活动实例启动。我就是这样称呼它的。

Intent intent = new Intent(context, A.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent,
PendingIntent.FLAG_UPDATE_CURRENT);

当离开小部件配置活动实例时,例如通过保存按钮单击启动器活动实例重新启动。

public void onClick(View v) {
        settings.save();

        // Signal that saving was performed and widget should be shown
        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        setResult(RESULT_OK, resultValue);

        BreakWidgetProvider.updateWidgets(new int[] { appWidgetId }, this);

        this.finish();
    }

活动应该属于不同的任务。我想知道为什么它们是相关的。

如何防止启动器活动实例重启?

【问题讨论】:

    标签: android android-intent android-activity widget android-pendingintent


    【解决方案1】:

    我解决了。 小部件配置活动实例似乎是由启动器启动的活动实例的子对象。所以我调整了清单如下。

    <activity
        android:name=".BreakMainActivity"            
        android:label="@string/app_name"
        android:launchMode="standard"
        **android:allowTaskReparenting="false"**
        **android:noHistory="true"**            
        android:theme="@android:style/Theme.Light" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    我想 allowTaskReparenting="false" 就足够了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      • 2011-09-01
      • 2010-12-28
      • 1970-01-01
      相关资源
      最近更新 更多