当前位置: 代码迷 >> Android >> android推延进入主界面代码 源码
  详细解决方案

android推延进入主界面代码 源码

热度:526   发布时间:2016-04-27 22:59:11.0
android延迟进入主界面代码 源码
?
延迟进入主界面的功能,主要用到Handler和Runnable,代码如下:
?
package?com.zx.app;
import?android.app.Activity;
import?android.content.Intent;
import?android.os.Bundle;
import?android.os.Handler;
import?android.view.View;
import?android.widget.Button;
public?class?StartScreenActivity?extends?Activity?{
?private?final?int?SPLASH_DISPLAY_LENGHT?=?3000;?//?3秒启动界面延迟
?private?Button?btn;
?@Override
?protected?void?onCreate(Bundle?savedInstanceState)?{
??//?TODO?Auto-generated?method?stub
??super.onCreate(savedInstanceState);
??setContentView(R.layout.splash);
??btn?=?(Button)?this.findViewById(R.id.enter);
??//创建一个线程
??final?Runnable?myRun?=?new?Runnable()?{
???@Override
???public?void?run()?{
????//?TODO?Auto-generated?method?stub
????Intent?intent?=?new?Intent(StartScreenActivity.this,
??????MainActivity.class);
????startActivity(intent);
????finish();
???}
??};
??final?Handler?handler?=?new?Handler();
??//使用handler对象来定时启动线程运行
??handler.postDelayed(myRun,?SPLASH_DISPLAY_LENGHT);
??
?//直接点击跳过?延迟加载进入主界面
?btn.setOnClickListener(new?View.OnClickListener()?{
???@Override
???public?void?onClick(View?v)?{
????//?TODO?Auto-generated?method?stub
????//移除handler延迟加载里面的线程,就不会存在执行两次的情况
????handler.removeCallbacks(myRun);
????Intent?intent?=?new?Intent(StartScreenActivity.this,
??????MainActivity.class);
????startActivity(intent);
????finish();
???}
??});
?}
}
?
?
项目源码来源:http://www.itlanbao.com/
  相关解决方案