运行固定时间的活动,然后开始另一个活动
答
您可以使用启动画面的概念来做到这一点。 请看下面的代码:
public class SplashScreen extends Activity {
protected boolean _active = true;
protected int _splashTime = 2000; // time to display the splash screen in ms
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread splashTread = 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.live.A"));
stop();
}
}
};
splashTread.start();
}
}
其中A是你想要的启动画面后,显示屏幕和com.live是你的包名
希望这将帮助你:)
答
new Handler().postDelayed(new Runnable() {
public void run() {
/* Create an Intent that will start the Second-Activity. */
Intent mainIntent = new Intent(YourFirstActivity.this,
YourSecondActivity.class);
YourFirstActivity.this.startActivity(mainIntent);
YourFirstActivity.this.finish();
}
}, 2000);
答
与上面几乎一样,添加了1个:屏幕上的触摸移除了Spashscreen:
public class SplashScreen extends Activity {
protected boolean _active = true;
protected int _splashTime = 5000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// thread for displaying the SplashScreen
Thread splashTread = 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();
GoToMain();
stop();
}
}
};
splashTread.start();
}
public void GoToMain(){
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
return true;
}
}
MainActivity是下一个活动的OFC :-)
快乐编码
感谢的家伙对你有所帮助的名称.... – 2011-03-31 05:52:52