我试图在第一次午餐后创建一个显示启动画面的webview应用程序 . 最初一旦我打开应用程序,启动屏幕将显示,然后在5秒后它将加载主要活动 VaultActivity
,但在我添加了代码行以检查之前是否已启动启动画面'SplashScreen'时,应用程序停止加载 VaultActivity
使用 SPLASH_TIME_OUT
我设置了,随时我在应用程序中午餐时仍会显示启动画面 .
Initially
public class SplashScreen extends Activity {
private static int SPLASH_TIME_OUT = 5000; // Splash screen timer
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Start main activity
Intent intent = new Intent(SplashScreen.this, VaultActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_TIME_OUT);
}
}
Currently
public class SplashScreen extends Activity {
private static int SPLASH_TIME_OUT = 5000; // Splash screen timer
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
if(pref.getBoolean("activity_executed", false)){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Start main activity
Intent intent = new Intent(SplashScreen.this, VaultActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_TIME_OUT);
} else {
SharedPreferences.Editor ed = pref.edit();
ed.putBoolean("activity_executed", true);
ed.commit();
}
}
}
My Manifest
<activity
android:name=".SplashScreen"
android:launchMode="singleTask"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".VaultActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="example.com"
android:pathPrefix="/androidmobile" />
</intent-filter>
</activity>
2 回答
你必须在你的其他地方调用startActivity .