在第三方浏览器中打开本地app某个activity 使得app多次启动的解决办法
来源:互联网 发布:ff14网络传输异常 编辑:程序博客网 时间:2024/04/29 05:26
在项目开发中,遇到了一个问题,通过第三方浏览器打开本地app的解决办法;
我们一般都是通过
<intent-filter> //这三方必须配置 <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="caifuapp" /></intent-filter>配置来启动,但是url启动与在手机桌面启动是打开了多个app,在手机上并不支持一个应用打开多次的情况所以会出现多次重启的情况
解决办法如下:
把主界面的启动模式改为singtask,把启动的activity的启动模式也改成singtask。
配置启动界面的scheme值
在启动界面判断主界面是否已经启动,假如已经启动直接跳过广告界面到达主界面启动需要展示的页面
如果没有,则启动广告业
protected void startAndExit(Intent i) { Intent intent = new Intent(this, HomepageActivity.class); if (i != null) { intent.setData(i.getData()); } ComponentName cmpName = intent.resolveActivity(getPackageManager()); boolean bIsExist = false; if (cmpName != null) { // 说明系统中存在这个activity ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfoList = am.getRunningTasks(10);// logi(TAG, "---startAndExit---taskInfoList.size:" + taskInfoList.size()); for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) { if (taskInfo.baseActivity.equals(cmpName)) { // 说明它已经启动了 bIsExist = true; break; } } } if (bIsExist) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);// intent.putExtra("isExit", (Boolean) true); //让它自行关闭 this.startActivity(intent); } else { Intent intent1 = new Intent(SplashActivity.this, StartActivity.class); if (i != null) { intent1.setData(i.getData()); } startActivity(intent1); } }如果某个Activity的运行模式被设置为singleTask或singleInstance,再次启动它,会触发它的onNewIntent方法。
@Overrideprotected void onNewIntent(Intent intent) { startAndExit(intent); finish(); super.onNewIntent(intent);}
@Override protected void onNewIntent(Intent intent) { logi(TAG, "---onNewIntent---"); super.onNewIntent(intent); if (intent.getBooleanExtra("isExit", false)) { finish(); // 自行关闭 } }
阅读全文
0 0
- 在第三方浏览器中打开本地app某个activity 使得app多次启动的解决办法
- 怎么在第三方应用中打开自己的APP
- ios中代码打开第三方app
- Android 仿照第三方app 将自己APP显示在打开列表中
- android APP中启动第三方地图
- 一个app打开另一个app的某个activity的问题
- js打开本地某个APP
- 使用第三方APP打开本地文档 (UIDocumentInteractionController)
- 从第三方打开APP
- 打开第三方地图App
- 根据app的名字启动第三方app
- Android 浏览器打开本地app
- Android 启动第三方app
- 在浏览器中打开手机app
- android 在浏览器中打开app
- android 读取本地安装app 包名并启动第三方app
- 浏览器中启动app
- android开发仿照第三方app打开方式,如何将你的app显示在打开列表,并且将文件复制到你的app应用内
- TCP/IP
- Viewpager滑动不流畅问题
- [LeetCode]66. Plus One
- SAS宏技术中,%let和call symput有什么区别?
- Android RecyclerView实现RadioButton绑定事件
- 在第三方浏览器中打开本地app某个activity 使得app多次启动的解决办法
- 2017年下半年小虎软考备考攻略
- 【Redis缓存机制】10.主从模式
- 安卓ListView的Item中添加按钮后,点击Button获取点击行的TextView文本数据
- python
- serialVersionUID的作用
- 新手的CSS前端框架设计,自适应浏览器变化
- python模块系列之
- Java简单实现浏览过的题号或页码或标签变色,下次登录依然保留