我有一個可操作的啓動畫面活動。但是,如果用戶點擊返回按鈕,並且在再次恢復應用程序後,我不想顯示splashscreen。我怎樣才能做到這一點 ?僅在新鮮開放時顯示Splashscreen
SplashScreen.java
public class SplashScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread t = new Thread() {
public void run() {
try {
int time = 0;
while (time < 4000) {
sleep(100);
time += 100;
}
}
catch (InterruptedException e) {
// do nothing
}
finally {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}
};
t.start();
}
}
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fardrop.radarso">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/app_theme">
<activity
android:name="com.fardrop.radarso.SplashScreen"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<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"
android:launchMode="singleInstance"
android:alwaysRetainTaskState="true"
android:icon="@mipmap/ic_launcher"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
</activity>
</application>
</manifest>
共享PREF和檢查是指https://stackoverflow.com/questions/20641580/show-splash-screen-one-time-only –
店閃屏狀態它在創建spalsh屏幕,如果用戶已經訪問它只是導航到主屏幕 –