我创建了如stackoverflow用户所说的启动画面,但仍然无法获得Android应用程序的启动画面,我的代码是
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
// thread for displaying the SplashScreen
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
boolean active = false;
while(active && (waited < 1000)) {
sleep(100);
if(active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
startActivity(new Intent(SplashScreenActivity.this,MainActivity.class));
finish();
//startActivity(new Intent("com.splash.com.MyApps"));
//startActivity( new Intent(getApplicationContext(), Myapps.class));
}
}
};
splashTread.start();
}
答案 0 :(得分:3)
只需复制此内容,然后根据文件修改进行更改。
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 2000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
答案 1 :(得分:2)
这样做......
@Override
protected void onCreate(Bundle savedInstanceState)
{
mythread thread = new mythread();
thread.start();
}
class mythread extends Thread
{
@Override
public void run()
{
super.run();
try
{
Thread.sleep(3000);
Intent i = new Intent(Splash_Screen.this,ArboristActivity.class);
finish();
startActivity(i);
}
catch (Exception e)
{
Log.v("log",e.toString());
}
}//End Run
}
并将splashScreenActivity放在您的清单文件中作为Launcher Activity ...就像这样..
<activity
android:name="com.app.Login.Splash_Screen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
答案 2 :(得分:1)
因为您正在使用active
初始化run
标记 {/ 1}}方法1>},所以它永远不会进入while ..它应该是。
false