本文介绍了安装后应用程序未保持状态 - Xamarin android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我在我的应用中注意到一件事.我为我的应用程序创建了 apk 说 ABC.apk 并复制到我的设备并通过单击它来安装它.安装成功完成后,我得到了 2 个选项完成"和打开",这是我们在安装后得到的常用选项.我单击打开"并运行该应用程序.我移到某个屏幕,将应用程序最小化并移到另一个应用程序,当我单击 ABC 时,它从我的第一个屏幕开始.我移回它只是几分之一秒,因此它不应该像第一次那样被杀死.

Recently I noticed one thing in my app.I created apk for my app say ABC.apk and copied to my device and installed it by clicking on it. After the installation got successfully completed, I got 2 options 'Done' and 'Open', the usual options we get after installation.I clicked on 'Open' and run the app. I moved to some screen and I minimized the app and moved to someother app, when I click my ABC, it started from my first screen.It was just fraction of seconds I moved back to it, hence it should not be killed though launched it like it is first time.

我注意到的几件事,如果我从后台运行的应用程序中明确杀死第一个实例并再次启动应用程序,它不会给我这个问题,如果我点击完成"而不是打开"它工作正常.

Few things I noticed I if I explicitly killed this first instance from background running apps and start the app again it is not giving me this problem, same if I click 'Done' instead of 'Open' it works fine.

有没有人遇到同样的问题,或者有什么解决方案?

Is there anyone who are facing same issue, or have some solution for it?

提前致谢.语气

推荐答案

问题是从安装程序启动应用程序的方式与 Android 从主屏幕启动应用程序的方式不完全匹配.因此,如果您最初从安装程序启动您的应用程序,当您稍后再次从主屏幕启动应用程序时,Android 不会识别该应用程序已经在运行,而只会创建根 Activity 的新实例 并将其添加到现有任务的任何现有活动之上.

The problem is the way that the app gets launched from the installer doesn't exactly match the way Android launches apps from the HOME screen. Because this, if you initially launch your app from the installer, when you then later launch the app again from the HOME screen, Android doesn't recognize that the app is already running and just creates a new instance of the root Activity and adds it to the existing task on top of whatever activities are already there.

这就是为什么,如果您杀死应用程序并从主屏幕重新启动它,您将永远不会看到这种奇怪的行为.

This is why, if you kill the app and start it again from the HOME screen, you won't ever see this strange behaviour.

这是一个令人讨厌的 Android 错误,它从一开始就存在并且仍然被破坏,尽管已经打开了无数关于它的问题并且行为是可重现且有据可查的.

This is a nasty Android bug which has been around since the dawn of time and is still broken, even though countless issues have been opened about it and the behaviour is reproducible and well-documented.

请参阅以下问题和问题:

See the following issues and questions:

我的回答中记录了一个解决方法重新启动主页按钮上的活动,但...只是第一次

There is a workaround documented in my answer toRe-launch of Activity on Home button, but...only the first time

这篇关于安装后应用程序未保持状态 - Xamarin android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:03
查看更多