0

我有麻烦了。当我将设备从横向转到纵向或在初始屏幕上反转时。我的主菜单在启动后运行了两次,我有两个主菜单,所以我被迫关闭一个。我该如何解决这个问题?

package tr.gov.egm.mobil;

import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.VideoView;


public class SplashActivity extends Activity{
 public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Window window = getWindow();
        window.setFormat(PixelFormat.RGBA_8888);
    }
 private void StartAnimations() {
 Animation anim = AnimationUtils.loadAnimation(this, R.anim.push_left_in);
 anim.reset();
 LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
 l.clearAnimation();
 l.startAnimation(anim);

 anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
 anim.reset();
 ImageView iv = (ImageView) findViewById(R.id.logo);
 iv.clearAnimation();
 iv.startAnimation(anim);



 }
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState)  {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    ImageView iv = (ImageView) findViewById(R.id.logo);
    if(isTablet(this)==true)
    {
        if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
        {
            iv.setImageResource(R.drawable.splashtel);
        } else {
            iv.setImageResource(R.drawable.splashtablet);
        }
    }
    else
    {
        if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
        {
            iv.setImageResource(R.drawable.splashtel);
        } else {
            iv.setImageResource(R.drawable.splashtablet);
        }
    }
    StartAnimations();

    Thread iplik = new Thread()
        {                
            public void run() {
                try {


                    sleep(4000);
                    Intent in = new Intent(
                            getApplicationContext(), MainMenuActivity.class);
                    startActivity(in);


                // Bu fonksiyon ile bir intent* tanımlanarak 2.ekran olan main.xml çağrılıyor

                } catch (InterruptedException e) {

                    e.printStackTrace();

                }  

                finally{

                    finish();

                }      

    }
        };

         iplik.start();  


}

public void onCompletion(MediaPlayer mp)
{
    Intent intent = new Intent(this, MainMenuActivity.class);
    startActivity(intent);
    finish();
}
public boolean isTablet(Context context) {
    boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
    boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    return (xlarge || large);
}

}
4

1 回答 1

0

只需覆盖onConfigurationChanged(Bundle savedInstance)方法并根据您的要求进行处理。

于 2013-07-12T19:50:22.587 回答