- protected void onStart() {
- Log_OC.d(TAG, "onStart en FileActivity");
- super.onStart();
- /// Validate account, and try to fix if wrong
- if (mAccount == null || !AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name)) {
- if (!AccountUtils.accountsAreSetup(getApplicationContext())) {
+ protected void onRestart() {
+ super.onRestart();
+
+ Account oldAccount = mAccount;
+ grantValidAccount();
+ if (mAccount != null && !mAccount.equals(oldAccount)) {
+ onAccountSet(false);
+ }
+ }
+
+
+ /**
+ * Validates the ownCloud {@link Account} associated to the Activity any time it is restarted.
+ *
+ * If not valid, tries to swap it for other valid and existing ownCloud {@link Account}.
+ *
+ * If no valid ownCloud {@link Account} exists, mAccount is set to NULL and the user is requested
+ * to create a new ownCloud {@link Account}.
+ */
+ private void grantValidAccount() {
+ boolean validAccount = (mAccount != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), mAccount.name));
+ if (!validAccount) {
+ // get most recently used account as default account
+ mAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+ if (mAccount == null) {