Android - different behaviour in release signed build?

天大地大妈咪最大 提交于 2019-12-05 02:02:39

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.

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.

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