资源文件配置,使其变成起始页
<activity android:name=".LodingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
布局
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/a" />
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:text="5s" />
主页面(跳转到登录页面)
/**
* 启动页面
*/
public class LoadingActivity extends AppCompatActivity {
private TextView tvTime;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acitivy_loading);
initView();
initData();
}
private void initView(){
tvTime = findViewById(R.id.tvTime);
}
int count=3;
private void initData(){
final TimerTask timerTask = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvTime.setText(count+"秒");
if (count==0) {
// TODO: 2018/11/9 跳转页面
jumpActivity();
}
}
});
count--;
}
};
Timer timer = new Timer();
timer.schedule(timerTask,1,1000);
}
private void jumpActivity(){
// TODO: 2018/11/9 是否登录
SharedPreferences sharedPreferences = getSharedPreferences(Constant.APP_CONFIG, Context.MODE_PRIVATE);
boolean is_login = sharedPreferences.getBoolean(Constant.IS_LOGIN, false);
if (is_login) {
Intent intent=new Intent(this,MainActivity.class);
startActivity(intent);
}else {
Intent intent=new Intent(this,LoginActivity.class);
startActivity(intent);
}
finish();
}
}
util文件(Constant)
/**
* app常量
*/
public interface Constant {
String APP_CONFIG="app_config";//sp文件的名字
String IS_LOGIN="is_login";//判断是否登录
}