【问题标题】:Activity start again over the old activity when rotate活动在旋转时从旧活动重新开始
【发布时间】:2014-08-01 14:01:18
【问题描述】:

我有两个初始屏幕,首先是静态的,然后在他启动第二个初始屏幕后随机切换不同的初始屏幕。我的问题是当开始第二个活动时,直到活动工作旋转手机第二个活动重新开始旧的活动。我担心因为当启动画面结束并且我的应用程序启动时,我得到了两个工作应用程序。

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-11
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多