Android安装应用后点击“打开”遇到的问题及解决

一、问题描述

当安装新应用时,安装完成后会出现一个“打开”和“完成”界面,点击完成没有问题,但是点击“打开”就出现了问题。

具体操作如下:

step1:打开应用收到更新提示(启动页检查更新),点击“立刻更新”

setp2:下载成功后点击“安装”,

setp3:安装成功后出现“打开”和“完成”界面,点击“打开”,应用先显示启动页面然后进入到主界面,

setp4:按下HOME键,回到桌面,然后点击桌面应用图标,会先显示启动页面然后再显示主界面。

二、问题原因

刚开始还以为是应用崩溃了,才重新打开了启动界面,后面经过测试和日志发现并没有任何的异常。What?遇见鬼了!经过搜索终于发现了问题的原因:

This is due to the intents being used to start the app being different. Eclipse starts an app using an intent with no action and no category. The Launcher starts an app using an intent with android.intent.action.MAIN action and android.intent.category.LAUNCHER category. The installer starts an app with the android.intent.action.MAIN action and no category.

原来这三种打开方式是有区别的,通过idea安装打开应用的intent是没有action和category的,桌面点击图标打开应用的intent是带有action(android.intent.action.MAIN) 和category(android.intent.category.LAUNCHER)的,而按照器打开应用只带有action(android.intent.action.MAIN)而没有category。

二、解决方式

再启动界面的onCreate添加方法添加如下代码

@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {

        // Activity was brought to front and not created,

        // Thus finishing this will get us to the last viewed activity

        finish();

        return;

    }

   ……

}

三、参考

https://stackoverflow.com/questions/6337217/how-to-return-to-the-latest-launched-activity-when-re-launching-application-afte

https://www.jianshu.com/p/eea14ca0b164

https://developer.android.google.cn/guide/components/tasks-and-back-stack

    原文作者:向前向后遇见改变
    原文地址: https://www.jianshu.com/p/ff0e40acc310
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞