Fix back stack when coming in from a widget or notification.

Also, got into a weird state and was able to find a few places
where null checks would be useful.
Change-Id: Ida4ac37d618ffb3736f1582351a58e5f86ab6e76
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index c1680f7..8bff494 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -111,6 +111,7 @@
     private FetchSearchFolderTask mFetchSearchFolderTask;
     /** Whether we have recorded this folder as a recent folder yet? */
     private boolean mFolderTouched = false;
+    private FetchInboxTask mFetchInboxTask;
 
     protected static final String LOG_TAG = new LogUtils().getLogTag();
     /** Constants used to differentiate between the types of loaders. */
@@ -273,6 +274,16 @@
         }
     }
 
+    // TODO(mindyp): set this up to store a copy of the folder locally
+    // as soon as we realize we haven't gotten the inbox folder yet.
+    public void loadInbox() {
+        if (mFetchInboxTask != null) {
+            mFetchInboxTask.cancel(true);
+        }
+        mFetchInboxTask = new FetchInboxTask();
+        mFetchInboxTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+    }
+
     /** Set the current folder */
     private void setFolder(Folder folder) {
         // Start watching folder for sync status.
@@ -753,6 +764,25 @@
         }
     }
 
+    private class FetchInboxTask extends AsyncTask<Void, Void, ConversationListContext> {
+        @Override
+        public ConversationListContext doInBackground(Void... params) {
+            // Gets the default inbox since there is no context.
+            return ConversationListContext.forFolder(mActivity.getActivityContext(), mAccount,
+                    (Folder) null);
+        }
+
+        @Override
+        public void onPostExecute(ConversationListContext result) {
+            mConvListContext = result;
+            setFolder(mConvListContext.folder);
+            if (mFolderListFragment != null) {
+                mFolderListFragment.selectFolder(mConvListContext.folder);
+            }
+            showConversationList(mConvListContext);
+        }
+    }
+
     private class FetchAccountFolderTask extends AsyncTask<Void, Void, ConversationListContext> {
         @Override
         public ConversationListContext doInBackground(Void... params) {