0

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:

  1. Launch the app, splash screen appears
  2. After 1 second, splash screen finishes and opens the main activity - so far, so good.
  3. I hit the home button, app goes to the background
  4. Call the app back - the splash screen is opened
  5. 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.

Community
  • 1
  • 1
Gil Moshayof
  • 16,633
  • 4
  • 47
  • 58
  • Could you paste your splash screen and manifest code? Also I would like to ask one thing, did you call finish() before launching intent from splash screen? – Adarsh Yadav Jul 28 '15 at 09:53
  • I call finish() on the splash screen immediately after launching the next activity. – Gil Moshayof Jul 28 '15 at 10:03

1 Answers1

0

Sorry but for a lack of reputation i can't comment. Can you add some code? like when you invoke main page, when you close splash screen and the code you added from the link you posted? it will make reply easier :)

EDIT: anyway, i found this post, and according to it i think you can use

@Override
protected void onPause()
{
    super.onPause();
    startActivity(getIntent().addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
}

hope it helped :)

Community
  • 1
  • 1
Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66