title: Simple Android Design Flow Inquiry for Login Activity and Main Activity
body: <p>I am wondering about a design question about android. I often have two activities to separate my login and my main activity (side note: main activity is usually a navigation drawer). I flow is usually like this:</p>
  
  <p>I was thinking of changing this to:</p>
  
  <p>What do people think?
  My issues:</p>
  
  <ol>
  <li>Which Activity really should be in the launcher drawer?</li>
  <li>I store authentication information whether they are logged in just in the SharedPreferences. This is how checkLogin() is performed and where data is stored after a successful attemptLogin().</li>
  <li>I don't want the user to be able to press the back button to access the Login. Only pressing a designated "Log out" Button should bring them back to the login Activity<img src="https://i.stack.imgur.com/8kkr8.png" alt="enter image description here">.</li>
  </ol>
  
  <p>This is an example of some code for the parts</p>
  
  <p>Part A:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      checkLogin();
  
      uprintDatabaseHelper = new uprintHelper(this);
      uprintDatabaseHelper.getWritableDatabase();
  
  
      setContentView(R.layout.activity_main_nav_drawer);
      mNavigationDrawerFragment = (NavigationDrawerFragment)
                  getFragmentManager().findFragmentById(R.id.navigation_drawer);
      mTitle = getTitle();
      // Set up the drawer.
      mNavigationDrawerFragment.setUp(
              R.id.navigation_drawer,
              (DrawerLayout) findViewById(R.id.drawer_layout));
  
  }
  </code></pre>
  
  <p>Part B:</p>
  
  <pre><code>SharedPreferences sharedPreferences = getSharedPreferences("UserData",MODE_PRIVATE);
  if(!sharedPreferences.getBoolean("LOGGED_IN", false))    {
      if(!sharedPreferences.getBoolean("DATABASE_EXIST", false))  {
          uprintDatabaseHelper = new uprintHelper(this);
          uprintDatabaseHelper.getWritableDatabase();
      }
      Intent intent = new Intent(this,LoginActivity.class);
      startActivity(intent);
  }
  </code></pre>
  
  <p>Part C:</p>
  
  <pre><code>final boolean attemptLogin(String user, HttpClient client)  {
      HttpPost post = new HttpPost(getString(R.string.authorization_url));
      String body;
      body = "email=" + user;
  
      post.setHeader("Content-type","application/x-www-form-urlencoded");
  
      try {
          post.setEntity(new StringEntity(body,"UTF-8"));
          try {
              HttpResponse response = client.execute(post);
              BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
              String json = reader.readLine();
              try {
                  JSONObject finalResult = new JSONObject(json);
  
                  return finalResult.getBoolean("success");
              } catch (JSONException e1) {
                  e1.printStackTrace();
              }
  
          } catch (ClientProtocolException e) {
              e.printStackTrace();
              return false;
          } catch (IOException e) {
              e.printStackTrace();
              return false;
          }
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      }
  
  
      return false;
  }
  </code></pre>
  
  <p>Part D:</p>
  
  <pre><code>SharedPreferences.Editor editor = sharedpreferences.edit();
  editor.putBoolean("LOGGED_IN", true);
  editor.commit();
  finish();
  </code></pre>