2016-12-15 54 views
20

步驟: 1)開啓Android應用程序(具有cordova建)Android應用開始更新停止

2)然後我打電話cordova-webintent安裝更新 https://github.com/Initsogar/cordova-webintent

3)我按下安裝並開始安裝,但幾秒鐘後,應用程序強制停止並關閉,而不是安裝並打開更新的應用程序。

這個問題出現前一段時間,我不明白爲什麼發生這種情況,因爲cordova-webintentcordova相同的版本。

4)應用程序強制停止後,點擊應用程序圖標,但出現消息「應用程序未安裝」。應用程序在幾秒鐘後繼續在後檯安裝。我再次點擊應用程序圖標,打開更新的應用程序。

請幫助解決這個問題與安裝時,應用程序強制停止。

日誌:

E:\工作\ hello1>亞行logcat ActivityManager:我com.example.hello1:d *:S

---------開始系統的

I/ActivityManager(715):【背景服務優先級調整]設置callerFg作爲假對service.getFlags():260

I/ActivityManager(715):START U0 {ACT = android.intent .action.VIEW dat = file:///storage/emulated/0/filename1.apk typ = application/vnd.android.package-archive cmp = com.android.packageinstaller/.PackageInstallerActivity} from uid 10657 on display 0

---------主開始

I/ActivityManager(715):START u0 {dat = file:///storage/emulated/0/filename1.apk cmp = com.android。 packageinstaller/.InstallAppProgress(具有額外)}從上顯示0 UID 10072 I/ActivityManager(715):[AppLaunch]顯示顯示com.android.packageinstaller/.InstallAppProgress:+ 135ms

I/ActivityManager(715):強制停止com.example.hello1 appid = 10657 user = -1:卸載pkg

I/ActivityManager(715):殺死19149:com.example.hello1/u0a657(形容詞1):停止com.example.hello1

W/ActivityManager(715):通知應用開關退出的packageName = com的.example.hello1 I/ActivityManager(715):強制結束活動ActivityRecord {16a2ad7e U0 com.example.hello1/.MainActivity t2758}

I/ActivityManager(715):強制結束活動ActivityRecord {32eb6933 U0 com.android .packageinstaller/.InstallAppProgress t2758}

W/ActivityManager(71 5):虛假的ProcessRecord死亡{2590ad4d 19149:com.example.hello1/u0a657},curProc for 19149:null

I/ActivityManager(715):Force stopping com。example.hello1的appid = 10657用戶= -1:更新PKG I/ActivityManager(715):強制關閉com.example.hello1的appid = 10657用戶= 0:PKG刪除

+0

你能提供一些像Android版本,科爾多瓦版本的更多信息,它是否是設備特定的?還有,你的應用程序在更新過程中是否會出現背景?請拋出一些光線,以深入挖掘 – Gandhi

+0

- Android 5.0.1 - 科爾多瓦6.3.1 - 我檢查了聯想和三星平板電腦。 - 是的,應用程序關閉,並在更新後進入背景 – IuliiaBoiko

+0

由於應用程序進入後臺,我懷疑intent事件可能不會像web意圖插件問題中提到的那樣觸發 - https://github.com/Initsogar/cordova-webintent/issues/27 https://github.com/Initsogar/cordova-webintent/pull/28請檢查鏈接,並讓我知道它是否有幫助 – Gandhi

回答

0

當你開始安裝意圖/操作,Android操作系統強制關閉正在運行的應用程序,然後清理舊的應用程序文件(基本上它將刪除它們 - 應用程序內部數據文件夾/沙箱除外),然後它複製新的應用程序文件此後您可以啓動應用程序

應用程序的關閉在安裝過程中是必要的,因爲應用程序正在運行時,它可能會保存文件鎖定,從而導致無法刪除舊文件

「強制停止」對話框是android不成功進程「退出信號」的標準行爲。您可以通過使用Thread.UncaughtExceptionHandler

public void uncaughtException(Thread t, Throwable e){ 
    e.printStackTrace() 
    System.exit(0);// exit the app normally, with 0 (OK) signal - will bypass the "force close" UI 
} 

我不建議使用上述伎倆來解決你的問題,覆蓋了整個「強行停止」機制 - 它的唯一目的是展示它讓你瞭解它是如何工作的,並最終幫助你

進一步排查爲了實現無縫自動升級的應用程序,你必須:

  1. 下載新的APK(必須由相同的證書和您現有的應用程序上簽字電話)
  2. 設置延遲安裝意圖/操作using PendingIntent延遲您的應用程序需要關閉的時間+一些緩衝時間取決於設備性能(例如,500ms-1sec是合理的)
  3. 退出當前運行應用程序System.exit(0)