恢复应用程序时忽略启动画面活动 - Android

时间:2014-04-25 10:46:25

标签: android android-activity splash-screen onresume

我想知道为什么我的应用程序在恢复应用程序时会忽略我的SplashScreen.java活动。如果我用" Back"按钮,启动时会出现启动画面,但是如果我使用主页按钮退出,则不会调用SplashScreen活动...... :(

我甚至添加了onResume事件,但是在恢复我的应用时,启动画面仍然不会出现。 谢谢!

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>    


...

3 个答案:

答案 0 :(得分:2)

试试这个..

改变这个..

Intent mainActivity = new Intent("com.exploreca.tourfinder.MainActivity");
startActivity(mainActivity);

Intent mainActivity = new Intent(Splash.this,MainActivity.class);
startActivity(mainActivity);

答案 1 :(得分:0)

public class SplashActivity extends AppCompatActivity {  

    Handler handler;
    private final int SPLASH_DISPLAY_LENGTH = 2000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        SplashStart();
    }

    private void SplashStart() {
        handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();


            }
        }, SPLASH_DISPLAY_LENGTH);
    }


    @Override
    protected void onResume() {
        super.onResume();

    }
}

/* just add on resume method inside do not start your splace method in `onResume` method...*/

答案 2 :(得分:-1)

当您单击后退按钮时,活动即将完成,当您返回时,闪屏会显示。那是因为再一次启动了应用程序。

当你点击主页按钮时,活动没有完成,但是它会进入后台,当你打开应用程序一次,然后同样的活动被买到前面。所以没有显示启动画面。

它在应用程序生命周期中的工作方式。

尝试在onPause活动中调用finish();方法。所以它将一直完成。或者尝试将noHistory添加到清单中的活动。希望这会对你有所帮助。