初始屏幕没有显示
我有两个类Splash.java
和Activity2.java
!!我曾尝试过简单的泼溅代码:初始屏幕没有显示
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>
我已经尝试了一些批判和每次我得到:警告:活动未开始,其当前任务已被带到前面,此后我的trial.class看起来屏幕 – Alok 2010-11-02 08:08:55
当项目已经运行并且您再次运行该项目时,会出现此警告。您首先在模拟器或设备中关闭该项目,然后尝试运行。 – 2010-11-02 08:17:49
嗨感谢您的回复!!我已经做到了这一点,即使我关闭了我的整个项目,干净,再次运行仍存在问题!我已经在清单文件中给出了条目!!我是在误解someting还没有........生命周期)几毫秒后!!是否是一个很好的方法 – Alok 2010-11-02 09:23:20
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
);
}
}
请重新格式化您的代码and.give更多细节。而不是新的线程尝试postDelayed(Runnable,它) – 2010-11-02 07:08:30