Search code examples
androidandroid-activitysplash-screenonresume

Splash screen activity ignored when resuming application - Android


I am wondering why my application ignores my SplashScreen.java activity when resuming the aplication. If I close it with the "Back" button, the splash screen comes up on start, but if I exit with the home button the SplashScreen activity is not being called...:(

I even added the onResume event, but the splash screen still wont come up when resuming my app. Thanks!!

SplashScreen.java

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        spashStart();

    }

    protected void onResume(){
        super.onResume();
        spashStart();
        }   


    private void spashStart() {
        Thread splashTimer = new Thread() {
            public void run(){
                try{
                    sleep(5000);
                    Intent mainActivity = new Intent("com.exploreca.tourfinder.MainActivity");
                    startActivity(mainActivity);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                  finish();
                }
            }
        };
        splashTimer.start();
    }

}

Maifest:

...

<uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/scena_logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" > 
        <activity
            android:name="com.exploreca.tourfinder.Splash"
            android:label="@string/app_name" >            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>            
        </activity>    
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >            
            <intent-filter>
                <action android:name="com.exploreca.tourfinder.MainActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>            
        </activity>
        <activity 
            android:name=".SettingsActivity"
            android:parentActivityName="com.exploreca.tourfinder.MainActivity">            
        </activity>
        <activity 
            android:name=".TourDetailActivity"
            android:parentActivityName="com.exploreca.tourfinder.MainActivity">            
        </activity>  
        <activity 
            android:name=".NotificationDetails"
            android:label="@string/title_activity_notifDetails_title"
            android:parentActivityName="com.exploreca.tourfinder.MainActivity">            
        </activity>  
        <activity 
            android:name=".SavedEvents"
            android:label="@string/title_activity_SavedEvents" 
            android:parentActivityName="com.exploreca.tourfinder.MainActivity">            
        </activity>    
        <activity 
            android:name=".FollowList"
            android:label="@string/title_activity_Urmarite" 
            android:parentActivityName="com.exploreca.tourfinder.MainActivity">            
        </activity>    


...

Solution

  • when you click back button actually the activity is getting finished and when you comes back the splash screen shows. That because once more the appliaction is starting.

    When you click home button the activity is not finishing but it goes to background and when you open the app oncemoe then the same activity is bought to front. so the splash screen is not shown.

    its how when it works through the lifecycle of the application.

    Try to call finish(); method in th onPause of the activity. So it will be finished all the time. Or try adding noHistory to the activity in the manifest. Hope this will help you.