Android 如何从一个APP中打开另外一个APP
2016-05-10 13:24
495 查看
众所周知,在一个APP内部,从一个页面跳转到另外一个页面是使用startactivity函数来实现的。
同样的,对于应用之间的跳转也是如此的。应用直接的跳转分为三种情况,为了方便描述,我加上有两个应用A和B,需求是要从A点击一个按钮,可以跳转到B,同时A要传数据给B,B能够接收并且处理:
1.从A跳转到B的主Activity,代码如下:
1.1如果B是应用是关闭的,那么在onCreate()函数中增加如下语句:
1.2 如何B应用是开启状态,那么在onRestart()函数中增加如下语句:
2.从A跳转到B的某个被设置为exported的activity,B应用的状态无关紧要,代码如下:
同样的,对于应用之间的跳转也是如此的。应用直接的跳转分为三种情况,为了方便描述,我加上有两个应用A和B,需求是要从A点击一个按钮,可以跳转到B,同时A要传数据给B,B能够接收并且处理:
1.从A跳转到B的主Activity,代码如下:
Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName comp = new ComponentName("com.nbg.baby", "com.nbg.baby.MainActivity"); intent.setComponent(comp); int launchFlags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED; intent.setFlags(launchFlags); intent.setAction("android.intent.action.VIEW"); Bundle bundle = new Bundle(); bundle.putString("from", "来自测试应用"); intent.putExtras(bundle); startActivity(intent);
1.1如果B是应用是关闭的,那么在onCreate()函数中增加如下语句:
Bundle bundle = this.getIntent().getExtras(); if(bundle!=null && bundle.getString("from")!=null){ Util.showToast(s_instance, bundle.getString("from"), Toast.LENGTH_LONG); }
1.2 如何B应用是开启状态,那么在onRestart()函数中增加如下语句:
Bundle bundle = this.getIntent().getExtras(); if(bundle!=null && bundle.getString("from")!=null){ Util.showToast(s_instance, bundle.getString("from"), Toast.LENGTH_LONG); }
2.从A跳转到B的某个被设置为exported的activity,B应用的状态无关紧要,代码如下:
ComponentName comp = new ComponentName("com.nbg.baby", "com.nbg.baby.ApiLoginActivity"); Intent intent = new Intent(); intent.setComponent(comp); intent.setAction(Intent.ACTION_VIEW); Bundle bundle = new Bundle(); bundle.putString("extra", "我来自星星"); intent.putExtras(bundle); context.startActivityForResult(intent, 1);
相关文章推荐
- 如何在iPhone应用上跳转到在AppStore上的评论页面
- iOS 获取汉字的拼音
- android 中自定义软件盘用于特需界面的输入
- android-----LayoutInflater的inflate方法详解
- Appium学习-关于Inspector
- Integrating FlywayDB In A Spring Framework Application
- app与后台的token、sessionId、RSA加密登录认证与安全解决方案
- android:documentLaunchMode
- iOS——在ARC下引入MRC文件
- objective-c - 基础篇 - KVO键值转换设计模式
- Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Lig
- iOS开发添加Reveal工具
- android动态设置TextView的textColor问题
- Android开发笔记之多媒体图像的处理
- js判断移动端是否安装某款app的多种方法
- Android图片压缩
- 内存管理(16.5.10)
- Android通用流行框架大全
- android studio Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
- iOS中AutoLayer自动布局流程及相关方法