title: Switching between three activities in Android?
body: <p>I have a scenario of three activities namely:</p>
  
  <ol>
  <li>MainActivity</li>
  <li>DerivedActivity</li>
  <li>ThirdPage</li>
  </ol>
  
  <p>I want to navigate between 1st to second and to third.</p>
  
  <p>here is my <strong>Manifest</strong> (AndroidManifest.xml)</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.example.implicitexplicit"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="14"
          android:targetSdkVersion="21" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              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=".DerivedActivity"&gt;&lt;/activity&gt;
          &lt;activity android:name=".ThirdPage"&gt;&lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>Now the Main Activity(MainActivity.java)</strong></p>
  
  <pre><code>package org.example.implicitexplicit;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  public void impliex(View v)
  {
      Intent intent=new Intent(this, DerivedActivity.class);
      startActivity(intent);
  
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  }
  </code></pre>
  
  <p><strong>The 2nd(DerivedActivity.java)</strong></p>
  
  <pre><code>package org.example.implicitexplicit;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.MenuItem;
  import android.view.View;
  public class DerivedActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.derived_activity);
      getActionBar().setDisplayHomeAsUpEnabled(true);
  }
  
  private void explicit(View v) {
          Intent intent = new Intent(this, ThirdPage.class);
          startActivity(intent);
      }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
  
      if (item.getItemId()==android.R.id.home) {
          finish();
      }
      return super.onOptionsItemSelected(item);
  }
  }
  </code></pre>
  
  <p><strong>and the Last Activity(ThirdPage.java)</strong></p>
  
  <pre><code>package org.example.implicitexplicit;
  import android.app.Activity;
  import android.os.Bundle;
  public class ThirdPage extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.thirdpage_activity);
      }
  }
  </code></pre>
  
  <p>In the DerivedActivity.java I am getting an warning </p>
  
  <pre><code>The method explicit(View) from the type DerivedActivity is never used locally
  </code></pre>
  
  <p><strong>The xml files are as follows</strong></p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:gravity="center_horizontal"
  android:orientation="vertical" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/eia"
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
  &lt;ImageView
      android:id="@+id/imageView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/ic_launcher" 
      android:contentDescription="@string/imgalt"/&gt;
  
  &lt;TextView
      android:id="@+id/textView2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/desc"
      android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/clickme" 
      android:onClick="impliex"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>derived_activity.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center_horizontal"
  android:orientation="vertical" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/derivedText"
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/clickme"
      android:onClick="explicit"
       /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>thirdpage_activity.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/thirdpageText"
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Error :</p>
  
  <pre><code>java.lang.IllegalStateException: Could not find a method explicit(View) in the activity class org.example.implicitexplicit.DerivedActivity for onClick handler on view class android.widget.Button with id 'button1'
  </code></pre>