android之launcher时序图and图标的建立
16lz
2021-12-04
android系统的homescreen 就是一个系统的launcher,由它来负责启动其他的Activity。
系统launcher的Activity
- <activity
- android:name="com.android.launcher2.Launcher"
- android:launchMode="singleTask"
- android:clearTaskOnLaunch="true"
- android:stateNotNeeded="true"
- android:theme="@style/Theme"
- android:screenOrientation="nosensor"
- android:windowSoftInputMode="stateUnspecified|adjustPan">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.HOME" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.MONKEY"/>
- intent-filter>
- activity>
首先launcher使用pickShortcut()方法调用pickActivity对象,pickActivity对象调用check Intent filter() and chose item(),返回一个Intent对象。如图
选中图标之后,会在HomeScreen上添加一个图标。
2.怎样创建android桌面图标,代码如下
在androd manifest.xml的Activity标签中添加创建图标的动作
然后在Activity中创建一个Intent对象
- <action android:name="android.intent.action.CREATE_SHORTCUT"/>
- Intent addShortcut;
- if(getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT))
- {
- addShortcut = new Intent();
- addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");
- addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
- addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(LauncherSimpleActivity.this,MainActivity.class)); //点击图标启动的Activity
- setResult(RESULT_OK, addShortcut);
- }else {
- setResult(RESULT_CANCELED);
- }
- finish(); //添加完成之后销毁这个Activity
更多相关文章
- 类和 Json对象
- gson使用在android使用例子
- Android(安卓)封装json数据
- Android(安卓)Studio修改apk命名
- Android(安卓)Widget 小部件(三) 在Activity中添加Widget
- android 自带图标介绍
- android SQLite数据库基本操作示例
- android 蓝牙通讯
- android文件下载