Android アプリで 3 秒間続く SplashScreen アクティビティがあり、その後 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 秒間表示して MainActivity に切り替える代わりに、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);
}
}