【发布时间】:2014-02-28 01:01:42
【问题描述】:
通过屏幕按钮进入主屏幕然后再次单击应用程序打开它时,启动屏幕不会完成,它只是返回到启动屏幕?为什么会这样
我正在调用finish();那么为什么它不会混淆
package com.webcraftbd.radio;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
public class SplashScreen extends Activity
{
// Set the display time, in milliseconds (or extract it out as a configurable parameter)
private final int SPLASH_DISPLAY_LENGTH = 3000;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
@Override
protected void onResume()
{
super.onResume();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
// Obtain the sharedPreference, default to true if not available
boolean isSplashEnabled = sp.getBoolean("isSplashEnabled", true);
if (isSplashEnabled)
{
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
//Finish the splash activity so it can't be returned to.
SplashScreen.this.finish();
// Create an Intent that will start the main activity.
Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
SplashScreen.this.startActivity(mainIntent);
}
}, SPLASH_DISPLAY_LENGTH);
}
else
{
// if the splash is not enabled, then finish the activity immediately and go to main.
finish();
Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
SplashScreen.this.startActivity(mainIntent);
}
}}
【问题讨论】:
-
试试这个: Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class); SplashScreen.this.startActivity(mainIntent);SplashScreen.this.finish();你应该先 startActivity 然后完成你的启动画面。
-
你为什么首先使用启动画面?这是一个 Android 反模式,违反了设计准则。
-
我尝试过让您知道它是否有效。因为在我看来,它让应用看起来更专业,所以很多应用使用闪屏可能会导致其他内容加载
-
这里有很多启动画面:stackoverflow.com/questions/21989199/…
-
谢谢 ;) 不知道为什么当前的没有工作,然后从你的管子上取下来,所以它应该可以工作,我之前运气好就完成了这个教程
标签: android android-activity splash-screen