代码之家  ›  专栏  ›  技术社区  ›  escargot agile

如何将标志添加到APPWIDGET_CONFIGURE意图?

  •  0
  • escargot agile  · 技术社区  · 12 年前

    我在上注册了一项活动 APPWIDGET_CONFIGURE :

        <activity android:name="com.tahanot.activities.NearbyStops">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>
    

    然而,此活动的行为与预期不符。它在现有堆栈中打开,当我按下“上一步”按钮时,它会将我带到其他活动,而不是关闭任务。理想情况下,我想要 应用程序小工具_图形 意图包括 FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_MULTIPLE_TASK .

    是否可以在中指定标志 AndroidManifest.xml ,如果没有,你会建议什么变通方法?

    3 回复  |  直到 12 年前
        1
  •  1
  •   appsroxcom    12 年前

    请考虑为activity元素指定launchMode属性。

    <activity android:launchMode="singleTask" android:name="com.tahanot.activities.NearbyStops">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
        </intent-filter>
    </activity>
    

    根据 official docs ,

    标志活动新任务

    在新任务中启动活动。如果任务已在运行 您现在开始的活动,该任务将被带到 恢复其最后状态的前台,并且活动接收 onNewIntent()中的新意图。

    这会产生与 “单个任务” launchMode值, 在上一节中讨论过。

    既然你提到你想要 FLAG_ACTIVITY_NEW_TASK 因此singleTask启动模式可能对您有效。

        2
  •  0
  •   Preet_Android    12 年前

    开始活动时使用此java代码

    Intent intent = new Intent(this,
            activityname.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    

    在这里,您可以像这样添加带有意向对象的标志。

    您也可以添加多个标志。

        3
  •  0
  •   escargot agile    12 年前

    这是我使用的清单声明,遵循appsroxcom对android的想法:launchMode:

    <activity
        android:name="com.tahanot.activities.NearbyStops"
        android:configChanges="orientation"
        android:label="@string/title_activity_stops_nearby"
        android:launchMode="singleTop"
        android:taskAffinity="com.tahanot.tasks.widgetConfiguration" > 
        <!-- android:launchMode makes sure the Back button doesn't navigate to another NearbyStops activity. 
             android:taskAffinity makes sure the Back button doesn't navigate to some other activity. -->
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
        </intent-filter>
    </activity>