我的 android 应用程序有一个 SplashScreen 活动,持续 3 秒,然后切换到 MainActivity。
MainActivity 播放声音,它有一个按钮。我的问题是当 SplashScreen 活动可见时会播放声音。
MainActivity 的 onResume 调用 run(),run() 休眠 2 秒并播放声音。
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
m.start();
try {
Thread.sleep((int) randomValue * 1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m.seekTo(0);
m.start();
cpu.setText(EranThatWillShortYourDouble(randomValue));
btn.setClickable(true);
}
@Override
protected void onResume() {
super.onResume();
run();
}
不是 SplashScreen 显示 3 秒并切换到 MainAcivity,而是持续 5 秒并在 SplashScreen 可见时播放声音。
我该怎么办?
编辑:这是我的 SplashScreen 活动:
public class SplashScreen extends Activity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}