新应用的知识整理-1-启动页
16lz
2021-01-26
一、在AndroidManifest.xml文件中定义自己应用的启动activity
android:name=".PagesForShow.Start_ad" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@style/android:Theme.Light.NoTitleBar" > android:name="android.intent.action.MAIN" /> android:name="android.intent.category.LAUNCHER" />
其中的Intent filter就声明了这个activity作为启动activity。 Intent filter:android中的activity、service、receiver等应用程序组件都可以使用Intent filter来声明它们支持的动作和数据。
Intent filter节点中可以添加的标签有action、category、data、android:host、android:mimetype、android:path、android:port、android:scheme。其中:
1、action是每个Intent filter都必须要有的。
2、category则是用来指定应该在哪种情况下执行声明的action。可以指定自己的category也可以使用android提供的标准值:ALTERNATIVE 、SELECTED_ALTERNATIVE、
DEFAULT、HOME、LAUNCHER、BROWSABLE等。
3、data指定该组件允许执行的数据类型。
二、完成启动页功能:作为广告页同时完成后台登录
我的启动页的布局文件和简单,就是一张作为广告的图片。
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bignerdranch.android.mfailab.PagesForShow.Start_ad"> android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/imageView2" android:background="@drawable/boot_page" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"/>
要求是广告显示两秒钟同时进行后台登录操作(后台登录是由服务完成的,会在后面的文字中讲到)。做法: String filename2="LoginDataStore";String field2="Password";final String flag2 = ForDataStoreAndRead.getSharePreString(Start_ad.this, filename2, field2);if (!flag2.equals("0")){ Intent i=new Intent (Start_ad.this, LongRunningService.class); startService(i);}
new Handler().postDelayed(new Runnable(){ @Override public void run() { if (flag2.equals("0")) {//如果读取结果时,对应字段没有值就会读取到0.而登出时系统也会将相应字段设置为0 Intent intent=new Intent(Start_ad.this,LoginActivity.class); startActivity(intent); } else { Intent intent=new Intent(Start_ad.this,LoginSuccess.class); startActivity(intent); } finish(); } }, SPLASH_DISPLAY_LENGHT);}
读取保存的字段进行判断。如果应用是第一次运行(即之前没有用户登录过)那就不启动服务,而是等广告结束后跳转到登录界面。
如果不是第一次运行,用户已经登录过了(我们的应用是自动保存用户名和密码的),那就开启服务进行后台登录。广告结束后直接跳转到登录成功界面。
更多相关文章
- android中的隐式intent跟显式intent的使用
- Android的Fragment中onActivityResult不被调用的解决方案(绝对管
- android用SharedPreferences保存登录账户密码
- Android运行模式 未验证
- 深入理解Activity启动模式
- 一触即发——App启动优化最佳实践
- Android判断是否首次登录
- Android(安卓)设置应用启动动画
- 【 Android(安卓)10 系统启动 】系列 -- Launcher(应用门户)