@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // get instances to upload Intent i = getIntent(); ArrayList<String> instances = i.getStringArrayListExtra(GlobalConstants.KEY_INSTANCES); if (instances == null) { // nothing to upload return; } SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String url = settings.getString(UserPreferences.KEY_SERVER, getString(R.string.default_server)); String authCredentials = settings.getString(UserPreferences.KEY_USERNAME, getString(R.string.username)) + ":" + settings.getString(UserPreferences.KEY_PASSWORD, getString(R.string.password)); mInstanceUploaderTask = (InstanceUploaderTask) getLastNonConfigurationInstance(); if (mInstanceUploaderTask == null) { // setup dialog and upload task showDialog(PROGRESS_DIALOG); mInstanceUploaderTask = new InstanceUploaderTask(); mInstanceUploaderTask.setUploadServer(url + "/fileUpload?"); mInstanceUploaderTask.setAuthCredentials(authCredentials); totalCount = instances.size(); // convert array list to an array String[] sa = instances.toArray(new String[totalCount]); mInstanceUploaderTask.execute(sa); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(t, "onCreate: " + ((savedInstanceState == null) ? "creating" : "re-initializing")); mAlertMsg = getString(R.string.please_wait); mAlertShowing = false; mUploadedInstances = new HashMap<String, String>(); setTitle(getString(R.string.app_name) + " > " + getString(R.string.send_data)); // get any simple saved state... if (savedInstanceState != null) { if (savedInstanceState.containsKey(ALERT_MSG)) { mAlertMsg = savedInstanceState.getString(ALERT_MSG); } if (savedInstanceState.containsKey(ALERT_SHOWING)) { mAlertShowing = savedInstanceState.getBoolean(ALERT_SHOWING, false); } mUrl = savedInstanceState.getString(AUTH_URI); } // and if we are resuming, use the TO_SEND list of not-yet-sent submissions // Otherwise, construct the list from the incoming intent value long[] selectedInstanceIDs = null; if (savedInstanceState != null && savedInstanceState.containsKey(TO_SEND)) { selectedInstanceIDs = savedInstanceState.getLongArray(TO_SEND); } else { // get instances to upload... Intent intent = getIntent(); selectedInstanceIDs = intent.getLongArrayExtra(FormEntryActivity.KEY_INSTANCES); } mInstancesToSend = new Long[(selectedInstanceIDs == null) ? 0 : selectedInstanceIDs.length]; if (selectedInstanceIDs != null) { for (int i = 0; i < selectedInstanceIDs.length; ++i) { mInstancesToSend[i] = selectedInstanceIDs[i]; } } // at this point, we don't expect this to be empty... if (mInstancesToSend.length == 0) { Log.e(t, "onCreate: No instances to upload!"); // drop through -- everything will process through OK } else { Log.i(t, "onCreate: Beginning upload of " + mInstancesToSend.length + " instances!"); } // get the task if we've changed orientations. If it's null it's a new upload. mInstanceUploaderTask = (InstanceUploaderTask) getLastNonConfigurationInstance(); if (mInstanceUploaderTask == null) { // setup dialog and upload task showDialog(PROGRESS_DIALOG); mInstanceUploaderTask = new InstanceUploaderTask(); // register this activity with the new uploader task mInstanceUploaderTask.setUploaderListener(InstanceUploaderActivity.this); mInstanceUploaderTask.execute(mInstancesToSend); } }