主屏幕可以从您的清单中触发。开始您的活动,您希望拥有如下主屏幕:
<activity
android:name="com.example.HomeScreenActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_home_screen"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如果您想在几毫秒后切换到下一个屏幕,请创建您的活动,如下所示:
public class HomeScreenActivity extends Activity {
protected boolean _active = true;
protected int _splashTime = 3000; // time to display the splash screen in ms
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Your Activity Title");
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_home_screen);
// thread for displaying the HomeScreen
Thread homeTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("com.example.SecondViewActivity"));
}
}
};
homeTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
return true;
}
}