Android - 发布签名版本中的不同行为?

发布于 2024-11-27 07:08:17 字数 518 浏览 0 评论 0原文

目前我的 Android 应用程序存在一些非常奇怪的“bug”,如果我从 Eclipse 运行它,它运行得很好,几乎完美。

它包含一个登录屏幕,在通过 Eclipse 运行时我可以访问并进入主屏幕。当我按主页键并返回到我的应用程序时,它会返回到应用程序所在的最后一个位置(活动)。

但是,当我发布签名构建并将其部署到设备上时,它会出现不同的行为,在浏览登录屏幕后我按主页,然后返回到应用程序,登录屏幕总是出现。

两个版本中的代码是相同的,唯一的区别是一个是使用默认的调试密钥库签名的,而另一个是使用我自己的发布密钥库签名的。

有人遇到过这个吗?真是令人困惑!

编辑:更多信息:

应用程序当前的工作方式如下:

启动主活动,然后调用登录活动,登录活动然后移动到我的应用程序核心活动。

我还发现,似乎是在安装后第一次运行时遇到问题,如果我运行该应用程序,强制关闭它,然后再次运行它,然后它就可以完美运行,没有任何问题。

那么这似乎是一件很奇怪的事情?

Having some really strange "bugs" with my Android application at the minute, it I run it from Eclipse it runs fine, pretty much perfect.

It contains a login screen that I can access and get to my main screen fine when running through Eclipse. When I press the home key and return to my application it returns to the last position (Activity) the application was in.

However when I release sign a build and deploy it on the device it has different behavior,after going through the login screen when I press home and then return to the application the login screen always appears.

Code is identical in both builds, only difference is one is signed with the default debug keystore while the other is signed with my own release keystore.

Has anyone come across this? Its really confusing!

EDIT: More info:

The application currently works like this:

Main activity is launched which then calls the login activity, login activity then moves to my app core activity.

I have also discovered that it appears to be on the first run after install that I have the issue, if I run the app, force close it and then run it again it then runs perfectly without any issue.

So it seems to be something really strange?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人生戏 2024-12-04 07:08:17

我知道这是一个老问题,但这个问题让我有些头痛,我在下面发布了解决方案,以防有人遇到同样的问题。

由于 Intent 的启动模式,调试和发布模式之间的“奇怪”活动流程有所不同。当您处于调试状态时,您可以按“运行”按钮来启动主活动。当您处于发布模式时,您安装了该应用程序,然后按“打开”应用程序按钮。

一旦从不同位置打开应用程序,意图就会改变并导致重新打开应用程序。最重要的是(感谢 Android 的架构)如果您有多个活动流,例如:Splash ->登录->主要->等等,然后您按“home”并从另一个位置重新打开应用程序,整个活动流程将重新启动,但旧活动将保留在堆栈中。对我来说,由于单例中的一些变量初始化,这导致了一些问题。

为了解决这个问题,您可以在 AndroidManifest 中为您的 Activity 设置不同的启动模式:

android:launchMode="singleTask"

此外,您还可以尝试使用 singleInstancesingleTop。每种启动模式都有不同的行为。

如果您在 Google Play 商店中发布了您的应用程序,则可以复制此问题。导航到商店中的应用程序,然后按“打开”按钮。应用程序启动后,按“主页”按钮并转到菜单屏幕并从此处打开您的应用程序。您将看到该应用程序已重新创建。

I know this is an old question, but this issue created me some headache and I'm posting the solution below in case of someone is having the same problem.

The "weird" activity flow is different between debug and release mode because of Intent's launch mode. When you're in debug, you press the "run" button in order to launch the Main Activity. When you're in release mode, you installed the app, then you press the "open" application button.

Once the Application is opened from different location, the Intent will change and will cause to reopen the app. On top of that (thanks to Android's architecture) if you had multiple activity flow, e.g: Splash -> Login -> Main -> etc. and you press "home" and reopen the application from a different location, the whole Activity flow is restarted, BUT the old activities will remain in the stack. For me, that's caused some problems because of some variable initialization within a Singleton.

In order to fix this, you can set different launch mode within AndroidManifest for your activities:

android:launchMode="singleTask"

also, you could try with singleInstance or singleTop. Each launch modes are having different behaviour.

You can replicate this issue if you have your Application published in Google Play Store. Navigate to your app within the Store and press the "Open" button. Once the app is launched, press the "home" button and go to your Menu screen and open your app from here. You will see that the app is recreated.

明媚殇 2024-12-04 07:08:17

您可以将 Eclipse 配置为使用相同的密钥库吗?

我使用 Ant 脚本,它使用与我发布的版本相同的密钥安装我的“调试”应用程序,所以我没有看到这个问题。

Can you configure Eclipse to use the same keystore?

I use an Ant script, which installs my 'debug' application with the same key used for my published versions, so I have not seen this issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文