Android安裝應(yīng)用后點(diǎn)擊“打開”遇到的問題及解決

一、問題描述

當(dāng)安裝新應(yīng)用時(shí),安裝完成后會(huì)出現(xiàn)一個(gè)“打開”和“完成”界面,點(diǎn)擊完成沒有問題,但是點(diǎn)擊“打開”就出現(xiàn)了問題。

具體操作如下:

step1:打開應(yīng)用收到更新提示(啟動(dòng)頁檢查更新),點(diǎn)擊“立刻更新”

setp2:下載成功后點(diǎn)擊“安裝”,

setp3:安裝成功后出現(xiàn)“打開”和“完成”界面,點(diǎn)擊“打開”,應(yīng)用先顯示啟動(dòng)頁面然后進(jìn)入到主界面,

setp4:按下HOME鍵,回到桌面,然后點(diǎn)擊桌面應(yīng)用圖標(biāo),會(huì)先顯示啟動(dòng)頁面然后再顯示主界面。

二、問題原因

剛開始還以為是應(yīng)用崩潰了,才重新打開了啟動(dòng)界面,后面經(jīng)過測試和日志發(fā)現(xiàn)并沒有任何的異常。What?遇見鬼了!經(jīng)過搜索終于發(fā)現(xiàn)了問題的原因:

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.

原來這三種打開方式是有區(qū)別的,通過idea安裝打開應(yīng)用的intent是沒有action和category的,桌面點(diǎn)擊圖標(biāo)打開應(yīng)用的intent是帶有action(android.intent.action.MAIN) 和category(android.intent.category.LAUNCHER)的,而按照器打開應(yīng)用只帶有action(android.intent.action.MAIN)而沒有category。

二、解決方式

再啟動(dòng)界面的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

http://www.itdecent.cn/p/eea14ca0b164

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、知識(shí)點(diǎn)回顧:Activity (一)、如何實(shí)現(xiàn)Activity頁面跳轉(zhuǎn)? 示例代碼: //第一種方式: Int...
    白話徐文濤閱讀 2,175評論 0 15
  • 1.Intent的用法: (1)Action跳轉(zhuǎn) 1、 使用Action跳轉(zhuǎn),當(dāng)程序AndroidManifest...
    彭文波_4118閱讀 6,041評論 0 7
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,847評論 0 10
  • Intent組件雖然不是四大組件,但卻是連接四大組件的橋梁,學(xué)習(xí)好這個(gè)知識(shí),也非常的重要。 一、什么是Intent...
    困惑困惑困惑閱讀 1,716評論 0 0
  • 終究沒有等到滬昆高鐵全線通車,急匆匆去了云南。在2016年初的春假。一共9天8晚的行程。云南的景點(diǎn)太多,9天的行程...
    喬伊Joyin閱讀 458評論 2 7

友情鏈接更多精彩內(nèi)容