【问题标题】:How to prevent activities to show up from background when transparent activity is opened from widget?从小部件打开透明活动时,如何防止活动从后台显示?
【发布时间】:2020-03-16 15:09:30
【问题描述】:

我正在使用 AndroidStudio,我有一个 Theme.Dialog 的活动

<activity
      android:name=".widgets.MiniTrackerConfigureActivity"
      android:theme="@android:style/Theme.Dialog"
      android:noHistory="true"
      android:excludeFromRecents="true">

通过点击App Widget打开,但是当我的应用在后台并且点击App Widget时,MiniTrackerConfigureActivity 在后台活动之上打开:

[后台应用] -> [App Widget] -> [App Widget clicked]


我想要的是不管应用程序是否在后台打开:
如果点击App Widget,则在主屏幕上打开活动

[App Widget] -> [App Widget clicked]


但如果应用在后台,则不应销毁应用或影响其活动堆栈!!

有可能吗?

【问题讨论】:

    标签: android android-studio android-appwidget


    【解决方案1】:

    您可以尝试定义一个 style 扩展 Theme.Dialog,如下所示:

    <style name="MyTheme" parent="@android:style/Theme.Dialog">
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowShowWallpaper">true</item>
    </style>
    

    values xml 文件中(例如:res/values/theme.xml) 他们在您的活动中使用这种风格:

    <activity
        android:name=".widgets.MiniTrackerConfigureActivity"
        android:theme="@style/MyTheme"
        android:noHistory="true"
        android:excludeFromRecents="true">
    

    这应该会导致与您描述的结果相似的结果 - 一个空白背景,仅显示设备壁纸,无论当前打开了哪些活动。

    【讨论】:

      【解决方案2】:

      我有完全相同的问题,并添加 android:launchMode="singleInstance" 到您的小部件活动应该会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-26
        相关资源
        最近更新 更多