我已將我的應用程序與txt文件關聯。 因此用戶可以在文件資源管理器應用程序中選擇一個文件並選擇我的應用程序來打開它。 在OnCreate中:android現有活動從OnResume讀取文件的意圖
Intent intent = getIntent();
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_VIEW)) {
txtFilePath = intent.getData().getPath();
}
然而,當用戶沒有關閉我的應用程序,他又回到資源管理器,打開另一個文件,在OnCreate不叫。 OnResusme被調用。 我把下面的代碼中的onResume:
Intent intent = getIntent();
String action = intent.getAction();
if (action != null && action.equals(Intent.MAIN)) {
txtFilePath = intent.getData().getPath();
}
然而,txtFilePath爲空。爲什麼?非常感謝您的幫助。
使用** txtFilePath /意圖**變量,全局和使用,如果沒有重新分配中的onResume ** txtFilePath /意圖** ()。 – Ajeesh
發佈您的清單 –