Webview 启动画面未按预期显示一次
Webview Splash screen doen't show once as expected
我正在尝试创建一个 webview 应用程序,在第一次午餐后显示一次启动画面。最初,一旦我打开应用程序,启动画面就会出现,然后在 5 秒后它将加载主 activity VaultActivity
,但是在我添加了代码行以检查启动画面是否 'SplashScreen'之前已经启动,应用程序停止加载 VaultActivity
使用我设置的 SPLASH_TIME_OUT
并且启动画面仍然在我午餐应用程序的任何时候出现。
最初
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);
}
}
目前
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();
}
}
}
我的清单
<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>
你必须在你的else中调用startActivity。
:) you need just adding startActivity in else section.
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);
final SharedPreferences.Editor ed = pref.edit()
if(pref.getBoolean("activity_executed", false)){
//ed.putBoolean("activity_executed", true);
//ed.commit();
Intent intent = new Intent(SplashScreen.this, VaultActivity.class);
startActivity(intent);
finish();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Start main activity
Intent intent = new Intent(SplashScreen.this, VaultActivity.class);
startActivity(intent);
ed.putBoolean("activity_executed", true);
ed.commit();
finish();
}
}, SPLASH_TIME_OUT);
}
}
}
我正在尝试创建一个 webview 应用程序,在第一次午餐后显示一次启动画面。最初,一旦我打开应用程序,启动画面就会出现,然后在 5 秒后它将加载主 activity VaultActivity
,但是在我添加了代码行以检查启动画面是否 'SplashScreen'之前已经启动,应用程序停止加载 VaultActivity
使用我设置的 SPLASH_TIME_OUT
并且启动画面仍然在我午餐应用程序的任何时候出现。
最初
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);
}
}
目前
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();
}
}
}
我的清单
<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>
你必须在你的else中调用startActivity。
:) you need just adding startActivity in else section.
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);
final SharedPreferences.Editor ed = pref.edit()
if(pref.getBoolean("activity_executed", false)){
//ed.putBoolean("activity_executed", true);
//ed.commit();
Intent intent = new Intent(SplashScreen.this, VaultActivity.class);
startActivity(intent);
finish();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Start main activity
Intent intent = new Intent(SplashScreen.this, VaultActivity.class);
startActivity(intent);
ed.putBoolean("activity_executed", true);
ed.commit();
finish();
}
}, SPLASH_TIME_OUT);
}
}
}