【问题标题】:Making a temporary Activity .. Like a hello screen制作一个临时 Activity .. 就像一个 hello 屏幕
【发布时间】:2015-02-03 17:23:56
【问题描述】:

我想制作一个允许我显示它的临时 Activity,例如它只显示 5 秒,所以我怎样才能使它 >> 就像我的应用程序开头的一个 hello 屏幕。

顺便说一句,我使用的是 Android Studio

【问题讨论】:

标签: java android-studio


【解决方案1】:

初始屏幕显示 2 秒,然后出现应用程序的主要活动。为此,我们添加了一个显示初始屏幕的 java 类。它使用一个线程等待 2 秒,然后使用一个意图启动下一个活动。

public class SplashScreen extends Activity {
private long ms=0;
private long splashTime=2000;
private boolean splashActive = true;
private boolean paused=false;
 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread mythread = new Thread() {
public void run() {
   try {
      while (splashActive && ms < splashTime) {
         if(!paused)
         ms=ms+100;
         sleep(100);
       }
   } catch(Exception e) {}
     finally {
     Intent intent = new Intent(SplashScreen.this, Splash.class);
     startActivity(intent);
     }
   }
 };
   mythread.start();
}
}

【讨论】:

  • 这是一种糟糕的飞溅方式。如果您在这 5 秒内关闭应用程序,主屏幕将再次出现。正确的方法是从主屏幕显示图像并在 5 秒后将其隐藏。
  • @sandalone : 现在可以了吗?
  • 在启动时间过去之前按主页按钮,你会明白我的意思
猜你喜欢
  • 1970-01-01
  • 2017-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-24
  • 1970-01-01
  • 2023-01-11
  • 1970-01-01
相关资源
最近更新 更多