私は2つのスプラッシュスクリーンを最初に静的に持っており、彼が2番目のスプラッシュスクリーンを開始した後、異なるスプラッシュスクリーンをランダムに切り替えます.私の問題は、2番目のアクティビティを開始し、アクティビティが機能するまで電話を回転させることです。画面が表示され、アプリが起動します。2つのアプリが動作しています。
これは私の最初の静的なスプラッシュ スクリーンです。
package com.readytechgo;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.widget.ImageView;
import android.app.Activity;
import android.content.Intent;
public class FirstSplashScreen extends DefaultActivity {
int timeout = 2000; // Choose the delay (1000 = 1 second)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
setFonts();
// Randomise a background
int[] yourListOfImages= {R.drawable.intro};
Random random = new Random(System.currentTimeMillis());
int posOfImage = random.nextInt(yourListOfImages.length);
ImageView imageView= (ImageView) findViewById(R.id.imageView1);
imageView.setBackgroundResource(yourListOfImages[posOfImage]);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//Redirecting to the home page
Intent redirect = new Intent(getApplicationContext(), SplashScreen.class);
startActivity(redirect);
finish();
}
}, timeout);
}
}
そして、これは私の 2 番目のスプラッシュ スクリーンです... 彼には問題があります....
package com.readytechgo;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.widget.ImageView;
import android.app.Activity;
import android.content.Intent;
public class SplashScreen extends DefaultActivity {
int timeout = 2000; // Choose the delay (1000 = 1 second)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.random_splash);
setFonts();
// Randomise a background
int[] yourListOfImages= {R.drawable.home_image1_portrait,R.drawable.home_image2_portrait,R.drawable.home_image3_portrait,R.drawable.home_image4_portrait};
Random random = new Random(System.currentTimeMillis());
int posOfImage = random.nextInt(yourListOfImages.length);
ImageView imageView= (ImageView) findViewById(R.id.randomImageView);
imageView.setBackgroundResource(yourListOfImages[posOfImage]);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//Redirecting to the home page
Intent redirect = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(redirect);
finish();
}
}, timeout);
}
}