private final static String MISSING_MOTOR_DIAG_FRAGMENT_TAG = "missingmotordialog";\r
private final static String MISSING_MOTOR_DOWNLOAD_FRAGMENT_TAG = "missingmotortask";\r
\r
+ /*\r
+ * Set to true when we have started to load a file. Is saved in InstanceState.\r
+ */\r
private boolean isLoading = false;\r
+ /*\r
+ * Set to the Uri of the file we are supposed to load. Is saved in InstanceState.\r
+ */\r
+ private Uri fileToLoad = null;\r
\r
@Override\r
protected void onPostCreate(Bundle savedInstanceState) {\r
Intent i = getIntent();\r
if (Intent.ACTION_VIEW.equals(i.getAction()) && i.getData() != null ) {\r
Uri file = i.getData();\r
- loadOrkFile(file);\r
+ fileToLoad = file;\r
+ loadOrkFile();\r
} else {\r
}\r
}\r
\r
@Override\r
protected void onSaveInstanceState(Bundle outState) {\r
- super.onSaveInstanceState(outState);\r
+ AndroidLogWrapper.d(OpenRocketLoaderActivity.class, "onSaveInstanceState");\r
outState.putBoolean("isLoading", isLoading);\r
+ if ( fileToLoad != null ) {\r
+ outState.putParcelable("fileToLoad", fileToLoad);\r
+ }\r
+ super.onSaveInstanceState(outState);\r
+ }\r
+\r
+ @Override\r
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {\r
+ AndroidLogWrapper.d(OpenRocketLoaderActivity.class, "onRestoreInstanceState");\r
+ isLoading = savedInstanceState.getBoolean("isLoading",false);\r
+ if ( savedInstanceState.containsKey("fileToLoad") ) {\r
+ fileToLoad = savedInstanceState.getParcelable("fileToLoad");\r
+ }\r
+ super.onRestoreInstanceState(savedInstanceState);\r
+ }\r
+\r
+ @Override\r
+ protected void onResume() {\r
+ AndroidLogWrapper.d(OpenRocketLoaderActivity.class, "onResume");\r
+ super.onResume();\r
+ // Start loading a file if we have a file and are not already loading one.\r
+ if ( fileToLoad != null && !isLoading ) {\r
+ loadOrkFile();\r
+ }\r
}\r
\r
/* (non-Javadoc)\r
*/\r
@Override\r
protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
+ AndroidLogWrapper.d(OpenRocketLoaderActivity.class, "onActivityResult");\r
switch ( requestCode ) {\r
case PICK_ORK_FILE_RESULT:\r
if(resultCode==RESULT_OK){\r
Uri file = data.getData();\r
- loadOrkFile(file);\r
+ fileToLoad = file;\r
+ // It would be nice to just start loading the file - but that doesn't work correctly.\r
+ // I'm uncertain if it is a bug in Android 14/15 or a bug in the v4 support library.\r
+ // essentially what happens is, when the FileBrowserActivity is brought up,\r
+ // this activity goes through the saveInstanceState calls to push it to the background.\r
+ // When the FileBrowserActivity returns the result, this.onActivityResult is called\r
+ // prior to any of the other lifecycle methods (onRestoreInstanceState as documented, but onStart is\r
+ // a bug. Since onStart hasn't been called, this activity is not able to create fragments - which \r
+ // are used to indicate progress etc.\r
+ // Instead of calling loadOrkFile() here, we push the file Uri into a member variable,\r
+ // then check the member variable in onResume to actuall kick off the work.\r
}\r
break;\r
default:\r
} \r
}\r
\r
- private void loadOrkFile( Uri file ) {\r
+ private void loadOrkFile( ) {\r
+ // a little protection.\r
+ if ( fileToLoad == null ) {\r
+ return;\r
+ }\r
isLoading = true;\r
- CurrentRocketHolder.getCurrentRocket().setFileUri( file );\r
- AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + file);\r
- String path = file.getPath();\r
+ CurrentRocketHolder.getCurrentRocket().setFileUri( fileToLoad );\r
+ AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + fileToLoad);\r
+ String path = fileToLoad.getPath();\r
File orkFile = new File(path);\r
\r
- getSupportFragmentManager().beginTransaction().add( OpenRocketLoaderFragment.newInstance(orkFile), "loader").commit();\r
+ // Also need commitAllowingState loss because of a bug in v4 dialog show.\r
+ getSupportFragmentManager().beginTransaction()\r
+ .add( OpenRocketLoaderFragment.newInstance(orkFile), "loader")\r
+ .commitAllowingStateLoss();\r
\r
}\r
\r