简体   繁体   English

在其他活动之上显示活动

[英]Show activity on top of other activity

I have an app that produces a notification when a process completes.我有一个应用程序会在流程完成时生成通知。 Upon clicking on the notification, a popup is created.单击通知后,将创建一个弹出窗口。 The popup is essentially an activity that isn't full screen.弹出窗口本质上是一个非全屏活动。

My issue is that if this popup is created on top of an open application, when the screen orientation changes, the background application is killed.我的问题是,如果在打开的应用程序之上创建此弹出窗口,则当屏幕方向更改时,后台应用程序将被终止。 I have attempted to circumvent this by forcing portrait mode (in the manifest and code) but that kills the background app as well when closing out of the popup.我试图通过强制纵向模式(在清单和代码中)来规避这一点,但是在关闭弹出窗口时也会杀死后台应用程序。

Does anyone know how to accomplish this without killing the background app when the configuration changes?有谁知道如何在配置更改时在不杀死后台应用程序的情况下完成此操作?

Add these lines in your manifest在清单中添加这些行

 <activity android:name=".Activity"
                 android:configChanges="keyboardHidden|orientation"         
                  android:label="@string/app_name">

then implement in your java code this override method然后在您的 java 代码中实现此覆盖方法

public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);}

With this you are telling your application to do nothing when config changes occur (orientation changes let's say) I had the same problem.有了这个,你告诉你的应用程序在配置更改发生时什么都不做(比如说方向更改)我遇到了同样的问题。 The whole activity was restarted, adding this, solved this issue.重新启动整个活动,添加这个,解决了这个问题。 I hope it does work for you too.我希望它也对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM