android:handle.postDelayed与removeCallbacks⽤法postDelayed⽅法和removeCallbacks⽅法的使⽤:
⽅法postDelayed的作⽤是延迟多少毫秒后开始运⾏,⽽removeCallbacks⽅法是删除指定的Runnable对象,使线程对象停⽌运⾏。postDelayed使⽤⽅法:
<strong>  </strong><pre name="code" class="java" >package com.way.activity;
t.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
TextUtils;
import com.way.util.PreferenceConstants;
import com.way.util.PreferenceUtils;
import R;
public class SplashActivity extends FragmentActivity {
private Handler mHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.splash);
mHandler = new Handler();
String password = PrefString(this,
PreferenceConstants.PASSWORD, "");
if (!TextUtils.isEmpty(password)) {
mHandler.postDelayed(gotoMainAct, 3000);
} else {安卓intent用法
mHandler.postDelayed(gotoLoginAct, 3000);
}
}
Runnable gotoLoginAct = new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, LoginActivity.class));
finish();
}
};
Runnable gotoMainAct = new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
};
}
removeCallbacks使⽤⽅法:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。