App is not maintaining the state after installation - Xamarin android

那年仲夏 提交于 2020-04-21 05:13:00

问题


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?

Thanks in advance. Prajakta


回答1:


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.

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:

  • https://issuetracker.google.com/issues/36941942
  • https://issuetracker.google.com/issues/36907463
  • https://issuetracker.google.com/issues/64108432
  • App restarts rather than resumes
  • Re-launch of Activity on Home button, but...only the first time

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




回答2:


Just some general comments that come to mind that you must consider that can cause problems.

  1. If you are trying to deploy an apk, did you switch from debug to release before building it? Make sure you are doing a full release. Do a clean and rebuild while in release mode as well.
  2. Did you sign the apk?
  3. Make sure all the necessary (if any) permissions are set in the manifest that will be needed by your app, on the device.

Hope these help point you in a direction.

Mike



来源:https://stackoverflow.com/questions/38119936/app-is-not-maintaining-the-state-after-installation-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!