错误:Theme.Translucent &FLAG_ACTIVITY_REORDER_TO_FRONT错误、Theme、Translucent、amp

2023-09-07 03:37:05 作者:稀有man※

我有一个半透明主题的活动:

android:theme="@android:style/Theme.Translucent.NoTitleBar"

这个问题也可以通过这个主题重现:

<style name="MyTheme" parent="@android:style/Theme"><item name="android:windowIsTranslucent">true</item><item name="android:windowBackground">@android:color/transparent</item><item name="android:colorBackground">@null</item></风格>
Win10应用更新错误803F7000解决办法

此活动在启动时加载并保存在内存中(当我启动此活动时,我将 FLAG_ACTIVITY_REORDER_TO_FRONT 标志添加为额外的).

问题:当我(从菜单)开始这个活动时,活动没有出现,什么也没有发生.但是:如果我删除半透明主题:一切正常,活动将回到前面.

是 onNewIntent() 被调用.

如果我按下半透明的活动是下面的活动!但它必须是顶级的.

一个例子

A(半透明活动)B C

堆栈:A

A startActivity(B)

堆栈:A,B

B startActivity(C)

堆栈:A、B、C

c startActivity(A)//带有标志 FLAG_ACTIVITY_REORDER_TO_FRONT

堆栈应该是:B,C,A

但是 A 永远不会被带到前面,尽管它的 onNewIntent() 被调用了.

有什么想法吗?

附注

有趣的未回答问题:http://groups.google.com/group/android-developers/browse_thread/thread/269c67f6b39cfe45?pli=1

不想使用 singleTasksingleInstance

android:launchMode.这些会更改后台堆栈并将活动移动到自己的堆栈中.因此,我们不再有 A、B、C.

singleTask 和 singleInstance — 不适合大多数人应用程序,因为它们产生的交互模型很可能对用户不熟悉并且与大多数其他人非常不同应用程序.

http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

任何想要直观表示launchModes的人都可以试试这个应用程序:https://play.google.com/store/apps/details?id=com.novoda.demos.activitylaunchmode

解决方案

如果我们不从AndroidManifest.xml设置主题,activity block和setContentView之前设置主题,在第一个半透明activity的onCreate方法中,问题是解决了,代码如下:

公共类 TranslucentActivityDemoActivity 扩展 Activity {@覆盖公共无效 onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);

 this.setTheme(R.style.myTheme);

 setContentView(R.layout.main);}

I have an activity with the translucent Theme :

android:theme="@android:style/Theme.Translucent.NoTitleBar"

Also the problem is reproduceable with just this Theme:

<style name="MyTheme" parent="@android:style/Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackground">@null</item>
</style>

This activity is loaded at startup and kept in memory (when I start this activity, I ad the FLAG_ACTIVITY_REORDER_TO_FRONT flag as extra).

Problem : when I start this activity (from the menu), the activity don't show up, nothing happens. But : if I remove the translucent theme : all works fine, the activity is back to front.

Yes onNewIntent() is called.

And if I press back the translucent activity is the one below! But it needs to be the top.

An example being

A ( translucent activity) B C

Stack: A

A startActivity(B)

Stack: A,B

B startActivity(C)

Stack: A,B,C

c startActivity(A) // with flag FLAG_ACTIVITY_REORDER_TO_FRONT

Stack should be: B,C,A

but A is never brought to the front, although its onNewIntent() is called.

Any ideas?

Side notes

Interesting unanswered question: http://groups.google.com/group/android-developers/browse_thread/thread/269c67f6b39cfe45?pli=1

android:launchMode of singleTask or singleInstance are not wanted to be used. These change the backstack and move activities into their own stack. Therefore we don't have A,B,C any more.

singleTask and singleInstance — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications.

http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

Anyone who wants a visual representation of launchModes try this app : https://play.google.com/store/apps/details?id=com.novoda.demos.activitylaunchmode

解决方案

If we do not set the theme from AndroidManifest.xml, activity block and set the theme before setContentView, in onCreate method in the first translucent activity, the problem is solved, below is the code:

public class TranslucentActivityDemoActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

      this.setTheme(R.style.myTheme);

        setContentView(R.layout.main);

    }

 
精彩推荐
图片推荐