Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未显示启动屏幕_Android - Fatal编程技术网

Android 未显示启动屏幕

Android 未显示启动屏幕,android,Android,我有两个类,分别是Splash.java和Activity2.java!!我尝试过splash的简单代码,如下所示: public class Splash extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout

我有两个类,分别是
Splash.java
Activity2.java
!!我尝试过splash的简单代码,如下所示:

public class Splash extends Activity 
    {
     @Override
     public void onCreate(Bundle savedInstanceState) 
     {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.splash);
      Thread thread= new Thread()
    {
     @Override
   public void run() 
     {

     super.run();
     startActivity(new Intent(Splash.this,Trial.class));
     finish();

   }
  };
  thread.start();

 }
}
在我的舱单上,我也提供了条目。我的代码正在运行,没有错误。R.layout.splash的代码如下:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 android:gravity="center_horizontal"
    >
<ImageView  
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/d"
android:layout_gravity="center"/>

</LinearLayout>

谢谢

这样试试

   setContentView(R.layout.splashscreen);

    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(2000);
                startActivity(new Intent(SplashScreen.this, Trial.class));
                finish();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }               
        }
    }).start();
xml文件

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:background="@drawable/screen1">
 </LinearLayout>

公共类启动扩展活动{
相对长度容器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
容器=(RelativeLayout)findViewById(R.id.container);
线程线程=新线程(){
@凌驾
公开募捐{
试一试{
睡眠(3000);//睡眠3秒钟
意图=新意图(Splash.this,Activity2.class);
intent.addFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
星触觉(意向);
完成();
}捕捉(中断异常e){
//e.printStackTrace();
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
super.run();
}
};
thread.start();
}
@凌驾
公共无效OnConfiguration已更改(配置newConfig){
super.onConfigurationChanged(newConfig);
//检查屏幕的方向
if(newConfig.orientation==Configuration.orientation\u横向){
//Toast.makeText(此为“横向”,Toast.LENGTH_SHORT).show();
设置大小();
}else if(newConfig.orientation==Configuration.orientation\u纵向){
//Toast.makeText(这是“肖像”,Toast.LENGTH_SHORT).show();
设置大小();
}
}
私有void setSize(){
if(容器!=null){
if(container.getChildCount()>0){
container.getChildAt(0).setMinimumHeight(getWindowManager().getDefaultDisplay().getHeight()*4/10);
}
}
}
}
**你的飞溅尖叫布局**
**显示**

}

请重新格式化您的代码,并提供更多详细信息。我尝试了许多方法,每次都得到:警告:活动未启动,它的当前任务已被带到前面,在此之后,我的试用版将在屏幕上显示此警告,当项目已经运行并且您再次运行项目时,会出现此警告。首先在模拟器或设备中关闭项目,然后尝试运行。谢谢回复!!我已经这样做了,即使我关闭了我的整个项目,清理,再次运行仍然存在问题!!!我也在清单文件中给出了条目!!几毫秒后,我是否还错了什么…(生命周期)!!这是一个很好的方法吗5年后:)thnaks,对不起,我刚刚加入了stack
    public class Splash extends Activity {
    RelativeLayout container;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.splashscreen);
        container = (RelativeLayout) findViewById(R.id.container);



        Thread thread = new Thread(){
            @Override
            public void run() {

                try {
                    sleep(3000);//sleeps for 3 second


                    Intent intent = new Intent(Splash.this,Activity2.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    finish();
                } catch (InterruptedException e) {
                 //   e.printStackTrace();
                    Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
                }


                super.run();
            }
        };
        thread.start();
    }



    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            //Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            setSize();
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            //Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
            setSize();
        }
    }

    private void setSize(){
        if(container!=null) {
            if (container.getChildCount() > 0) {
                container.getChildAt(0).setMinimumHeight(getWindowManager().getDefaultDisplay().getHeight() * 4 / 10);
            }
        }
    }


}

** your splash screeen layout **

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/shaded_rectangle"
    android:id="@+id/container">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/splas"/>
</RelativeLayout>


**manifest**



       <activity
            android:name=".collegeconnect.activity.Splash"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
public class MainActivity extends AppCompatActivity {

private static int SPLASH_TIME_OUT = 4000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new Handler().postDelayed

    (
    new Runnable()
    {
    @Override
    public void run ()
    {
    Intent i = new Intent(MainActivity.this, HomeActivity.class);
    startActivity(i);
    finish();
    }
    },SPLASH_TIME_OUT
    );
}