I'm experiencing a very strange issue which only occurs in release versions.
My app implements a splash screens which clears itself after a 1 second delay and launches the main activity. The splash screen is declared in my manifest with MAIN / LAUNCHER intent filters.
When debugging the app, everything works as expected (I'm using Android Studio 1.3 by the way).
However, here's what happens when I launch the app in release:
- Launch the app, splash screen appears
- After 1 second, splash screen finishes and opens the main activity - so far, so good.
- I hit the home button, app goes to the background
- Call the app back - the splash screen is opened
- After 1 second, the splash screen is removed and the main activity is opened in its original state.
If I kill the app and open it again, this bug disappears and doesn't appear again until I re-install the app.
I looked at this post and implemented the work-around there, and it seems to solve the problem, but I am very concerned about this bug nonetheless, and was wondering if anyone else saw something like this occur lately (the post is very old and suggests that the issue might be related to eclipse).
Edit
Here's the code I added to my splash screen activity (from the post linked above):
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0)
{
// call code which launches the main activity here
finish();
return;
}
As I said, this added code removes the problem, but I'm trying to understand why this problem occurs in the 1st place? Why is this only happening in release versions, and why is it only happening the 1st time the app is installed and stops happening once the app is killed and restarted?
The new activity is opened with the following intent flags: FLAG_ACTIVITY_SINGLE_TOP
& FLAG_ACTIVITY_CLEAR_TOP
Here is the relevant part of my manifest:
<activity
android:name="com.my.app.SplashScreenController"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/LightTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It's a bit difficult to post the exact code which opens the next activity since my app logic is somewhat complex and the next activity that is opened greatly depends on the variant & internal app state.