android启动另一应用
http://www.2cto.com/kf/201203/122910.html
Android SDK中有这样一个API:
public abstract Intent getLaunchIntentForPackage (String packageName)
如果packageName存在返回入口Intent, startActivity(Intent)可以启动应用,否则返回nullimport android.app.Activity;
下面有个小示例:
- import android.content.Intent;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- import android.os.Bundle;
- import android.view.View;
- public class Main extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- PackageManager packageManager = getPackageManager();
- Intent intent=new Intent();
- intent =packageManager.getLaunchIntentForPackage("pkgName");
- if(intent==null){
- System.out.println("APP not found!");
- }
- startActivity(intent);
- }
- }
- //-----启动我们自身写的程序------------------
- mButton01.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v) {
- //-----核心部分----- 前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名
- Intent intent=new Intent();
- intent.setComponent(new ComponentName("com.droidnova.android.games.vortex",
- "com.droidnova.android.games.vortex..Vortex"));
- startActivity(intent);
- }
- });
- //-----启动系统自带的应用程序------------------
- mButton02.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v) {
- Intent intent=new Intent();
- intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));
- startActivity(intent);
- }
- });
//这些代码是启动另外的一个应用程序的主Activity,当然也可以启动任意一个Activity
ComponentName componetName = new ComponentName(
//这个是另外一个应用程序的包名
"com.poynt.weibo",
//这个参数是要启动的Activity
"com.poynt.weibo.ui.IndexActivity");
Android在一个应用中启动另一个应用的Activity
为 activity 添加 intent-filter 的定义。
通过测试发现,只要添加如下语句,activity就可以被正常调用:
<intent-filter>
<action android:name=""/>
</intent-filter>
相应的启动代码为:
Intent intent = new Intent();
intent.setClassName(<package name>, <class name>);
startActivity(intent);
Activity1隐式调用Activity2时需要在AndroidManifest.xml文件中配置Activity2的action和category,具体添加下面的代码到Activity2的定义中
<intent-filter>
<action android:name="myaction2"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="mycategory" />
</intent-filter>
接着同样使用intent来启动Activity,代码如下:
Intent intent = new Intent("myaction2");
intent.addCategory("myCategory");
startActivity(intent);
这样就可以启动Activity2
android启动另一应用的更多相关文章
- android 启动模式介绍
Android启动模式 (1)Task:与Android系统是个多任务的系统中的任务是不同的.后者更倾向于多进程和多线程来说的,而这里的任务与application(应用程序)和activity(活动 ...
- 深入浅出 - Android系统移植与平台开发(四)- Android启动流程
作者:唐老师,华清远见嵌入式学院讲师. 一.Android init进程启动 还是从Linux的启动开始吧.Linux被bootloader加载到了内存之后,开始运行,在初始化完 Linux运行环境之 ...
- 深入浅出 - Android系统移植与平台开发(六)- 为Android启动加速
作者:唐老师,华清远见嵌入式学院讲师. Android的启动速度一直以来是他的诟病,虽然现在Android设备的硬件速度越来越快,但是随着新 版本的出现,其启动速度一直都比较慢,当然,作为程序员,我们 ...
- 解决android 启动白屏问题
Android 启动APP时黑屏白屏的三个解决方案 http://www.cnblogs.com/liqw/p/4263418.html android:windowSoftInputMode属性使用 ...
- Android 启动过程简析
首先我们先来看android构架图: android系统是构建在linux系统上面的. 所以android设备启动经历3个过程. Boot Loader,Linux Kernel & Andr ...
- Android 启动模拟器是出现“Failed to allocate memory: 8”错误提示的原因及解决办法
某天,Android 启动模拟器是出现“Failed to allocate memory: 8”错误,模拟器无法启动,如下图: 原因:设置了不正确AVD显示屏模式,4.0版默认的模式为WVGA800 ...
- 我的Android最佳实践之—— Android启动画面的实现方法
本文实例讲述了Android启动画面的实现方法.分享给大家供大家参考.具体分析如下: 在应用程序中经常用到启动画面,会启动一个后台线程为主程序的运行准备资源.Android要实现启动画面可以这样做: ...
- Android 核心分析 之八Android 启动过程详解
Android 启动过程详解 Android从Linux系统启动有4个步骤: (1) init进程启动 (2) Native服务启动 (3) System Server,Android服务启动 (4) ...
- Android启动过程以及各个镜像的关系
Android启动过程 Android在启动的时候,会由UBOOT传入一个init参数,这个init参数指定了开机的时候第一个运行的程序,默认就是init程序,这个程序在ramdisk.img中.可以 ...
- android130 android启动
Android的编译环境只支持Linux和Mac OS,google推荐使用64位操作系统, ### android启动 > #### 当引导程序启动Linux内核后,会加载各种驱动和数据结构, ...
随机推荐
- BNU 12846 LCM Extreme 最小公倍数之和(线性欧拉筛选+递推)
LCM Extreme Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Orig ...
- vue.js源码学习分享(九)
/* */ var arrayKeys = Object.getOwnPropertyNames(arrayMethods);//获取arrayMethods的属性名称 /** * By defaul ...
- vue.js源码学习分享(四)
/** * Generate a static keys string from compiler modules.//从编译器生成一个静态键字符串模块. */ function genStaticK ...
- hdu 4941 2014 Multi-University Training Contest 7 1007
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- Day 16 之二 省市县三级联动
摘录自:雨神,供参考! province_dic = { "河北": { "石家庄": ["鹿泉", "藁城", &qu ...
- iphoneXR的tabbar底部图片的适配
在自定义tabbar的背景图时,发现在ihonexr上有点问题,主要是因为iphoneXr用的是二倍图,但是Xr的tabbar底部高度多了34像素,所以就出现了如下的情况: 解决这个问题,还比较简单, ...
- vSphere Client 更改 ESX/ESXi 主机的端口
https://blog.csdn.net/hanzheng260561728/article/details/51283808?locationNum=8&fps=1
- js-classList修改class属性
classList定义与用法 1)classList属性返回元素的类名,作为DOMTokenList对象 2)该属性用于在元素中添加,移除及切换css类 3)classList属性是只读的,但可以用a ...
- Java中判断String对象是否为空的方法
Java原生的方法: String对象中有一个isEmpty的方法判断是否为空,其实isEmpty完全等同于string.length()==0,注意如果String本身是null,那么使用strin ...
- 【spring data jpa】使用repository进行查询,使用userRepository.getOne(id)和userRepository.findById(id)无法从数据库查询到数据
如题: 使用repository进行查询,使用CrudRepository自带的getOne()方法和findById()方法查询,数据库中有这条数据,但是并不能查到. userRepository. ...