旋转时,活动将再次从旧活动开始

时间:2014-08-01 14:01:19

标签: android out-of-memory splash-screen dynamic-splash-screen

我有两个Splash屏幕首先是静态的,然后他开始第二个闪屏,随机切换不同的闪屏。我的问题是当开始第二个活动,直到活动工作旋转电话第二个活动再次开始旧的。我担心因为当启动屏幕并且我的应用程序启动时,我有两个工作应用程序。

这是我的第一个静态启动画面。

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);
    }
}

这是我的第二个闪屏......和他一起我有问题......

 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);
    }
}

1 个答案:

答案 0 :(得分:-1)

您可以在清单xml上添加管理配置更改。

<activity
        android:name="youractivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name" >
    </activity>