title: always return to Login screen
body: <p>I have an app start by <code>Splash activity screen</code> for 5 seconds Then open <code>Login activity screen</code> then after you put correct user and password open the <code>Menu activity (listActivity)</code> then each row click open <code>MyCity activity</code>.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p><strong>What I'm trying to get is:</strong> where ever you are in my app, and you go away from my app for any reason <strong>not only when you press the home button</strong> but also FOR EXAMPLES:</p>
  
  <ol>
  <li><p>You press home button to check another app then want to return to my app .</p></li>
  <li><p>You have notification show new message on whatsup or email, you open your whatsup or open email, then return to my app .</p></li>
  </ol>
  
  <p>3- You left your mobile for period of time then you want to check my app again .</p>
  
  <p>4- you press power button to close the phone ( lock the screen) , then open the lock and want to return back to my app .</p>
  
  <p>what I mean any time you go away my app for any reason but whithout press <strong>back back back</strong> button which will exit the whole app 
  then want to return again to my app must open to 
   you <strong>the login screen</strong> to re enter your usename and password again. </p>
  
  <p>I Called <code>finish();</code> for both Splash activity and Login activity .</p>
  
  <p>I tried:<code>android:clearTaskOnLaunch="true"</code> in the Login activity in the manifest but it doesn'thing.</p>
  
  <p>Any advice will be appreciated, </p>
  
  <p><strong>PLEASE WRITE FULL WORKING CODE.</strong></p>
  
  <p>LOGIN ACTIVITY:</p>
  
  <pre><code> public class Login extends Activity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.login);
  
      Button b = (Button) findViewById(R.id.loginbutton);
  
    b.setOnClickListener(new OnClickListener() {
  
    public void onClick(View v) {
  
      EditText username = (EditText) findViewById(R.id.login);
      EditText password = (EditText) findViewById(R.id.password);
  
       if(username.getText().toString().length() &gt; 0 &amp;&amp; password.getText().
               toString().length() &gt; 0 ) {
  if(username.getText().toString().equals("test") &amp;&amp; password.getText().
               toString().equals("test")) {
  
  
      Intent intent = new Intent(Login.this, Menu.class);
      startActivity(intent);
         finish(); }
              }   }               
                      });  }  }
  </code></pre>
  
  <p>Menu Activity : </p>
  
  <pre><code>  public class Menu extends ListActivity {
  
        String classes[] = { "City1", "City2", "City3", "City4", "City5"};
  
            @Override
        protected void onCreate(Bundle savedInstanceState) {
           // TODO Auto-generated method stub
           super.onCreate(savedInstanceState);
  
        setListAdapter(new ArrayAdapter&lt;String&gt;(Menu.this,
          android.R.layout.simple_list_item_1, classes));
                                     }
  
       @Override
         protected void onListItemClick(ListView l, View v, int position, long id) {
           // TODO Auto-generated method stub
            super.onListItemClick(l, v, position, id);
           String cheese = classes[position];
     try {
      Class ourClass = Class.forName("com.test.demo.MyCity");
      Intent ourIntent = new Intent(Menu.this, ourClass);
      ourIntent.putExtra("cheese", cheese);
           startActivity(ourIntent);
             } catch (ClassNotFoundException e) {
          e.printStackTrace();
                              }
                      }}
  </code></pre>
  
  <p>MyCity Activity :  </p>
  
  <pre><code>   public class MyCity extends Activity {
  TextView tv1;
  String city;
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.city);  
  
      initializeTextViews();}
  
  private void initializeTextViews() {
  
      tv1=(TextView)findViewById(R.id.city_tv);
       city=getIntent().getStringExtra("cheese");
  
  if(city.equalsIgnoreCase("City1")){
  
          tv1.setText(Html.fromHtml(getString(R.string.city1)));}
  
  
      else if(city.equalsIgnoreCase("City2")){
  
          tv1.setText(Html.fromHtml(getString(R.string.city2)));}
  
  
      else if(city.equalsIgnoreCase("City3")){
  
          tv1.setText(Html.fromHtml(getString(R.string.city3)));}
  
  
      else if(city.equalsIgnoreCase("City4")){
  
          tv1.setText(Html.fromHtml(getString(R.string.city4)));}
  
  
      else if(city.equalsIgnoreCase("City5")){
  
          tv1.setText(Html.fromHtml(getString(R.string.city5)));}
  
  
      }}
  </code></pre>
  
  <p>MY MANIFEST:
  </p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.test.demo"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="15" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
  
          &lt;activity
              android:name=".Splash"
              android:label="@string/app_name"&gt;   
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name=".Login"
              android:label="@string/app_name" 
                   android:clearTaskOnLaunch="true"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.test.demo.LOGIN" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name=".Menu"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.test.demo.MENU" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
                &lt;activity
              android:name=".MyCity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.test.demo.MYCITY" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>SECOND UPDATE</strong> : i reached halfway to what i want but still some steps i can't achieve it  explained as below :</p>
  
  <p>BY applying  <code>android:clearTaskOnLaunch="true"</code> to Splash activity , </p>
  
  <p>and prevent back button behaviour on Menu activity :</p>
  
  <pre><code>  @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
         moveTaskToBack(true);
         return true;
              }
      return super.onKeyDown(keyCode, event);
                      } }
  </code></pre>
  
  <p>SO now when press home button away my app then return to my app its:</p>
  
  <p>go directly to <strong>Login activity</strong>.</p>
  
  <p><strong>but main goal now is :</strong></p>
  
  <p>if :</p>
  
  <p><strong>SCREEN LOCKED</strong> when you are away from your  mobile , or press lightly the power button to lock the phone .</p>
  
  <p>or</p>
  
  <p><strong>OPENED MESSAGE</strong> from notification</p>
  
  <p>or</p>
  
  <p><strong>OPENED EMAIL</strong>  from notification</p>
  
  <p>or</p>
  
  <p>you have <strong>CALL</strong> and answer it , </p>
  
  <p>THEN return to my app <strong>it does not go to login activity</strong> but you will return to the page where you was befor .</p>
  
  <p>ANY ADVICE PLEASE , THANKS.</p>
  
  <p><strong>THIED UPDATE :</strong> </p>
  
  <p>i used another code for override home button and control the back button rather than appling :<code>android:clearTaskOnLaunch="true"</code> to Splash activity in manifest , just apply the down code to Menu activity:</p>
  
  <pre><code>     @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
         moveTaskToBack(true);
           return true;}
  
      else if (keyCode == KeyEvent.KEYCODE_HOME) { 
       Intent i=new Intent(Menu.this,Login.class);
         startActivity(i);
            finish();
          return true;}
      return super.onKeyDown(keyCode, event);}
  </code></pre>