闪屏页开发

来源:互联网 发布:earth music知乎 编辑:程序博客网 时间:2024/06/07 03:30

闪屏页一般是用来创建快捷方式或者其他数据的初始化:

@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_splash);// 创建快捷方式createShortcut();// 进入引导页enterGuide();}

1,创建快捷方式:

/** * 创建快捷方式 */private void createShortcut() {// TODO Auto-generated method stub// 广播类型Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");// 快捷方式名字shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));// 设置是否重复创建shortcut.putExtra("duplicate", false);Intent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_LAUNCHER);// 设置点击快捷方式进入的页面intent.setClass(this, SplashActivity.class);shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// 创建快捷方式图标ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);sendBroadcast(shortcut);}
记得在清单文件添加权限:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
2,延时两秒进入引导页面:
/** * 延时两秒进入引导页面 */private void enterGuide() {// TODO Auto-generated method stubTimer timer = new Timer();TimerTask timerTask = new TimerTask() {@Overridepublic void run() {// TODO Auto-generated method stubIntent intent = new Intent(SplashActivity.this, GuideActivity.class);startActivity(intent);}};timer.schedule(timerTask, 1000);}



0 0
原创粉丝点击