Using Intent to show other Activities : Intent « Core Class « Android






Using Intent to show other Activities

    

package app.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Test extends Activity {
  OnClickListener listener1 = null;
  OnClickListener listener2 = null;
  OnClickListener listener3 = null;
  OnClickListener listener4 = null;
  Button button1;
  Button button2;
  Button button3;
  Button button4;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    prepareListeners();
    setContentView(R.layout.main);
    button1 = (Button) findViewById(R.id.activity_main_button1);
    button1.setOnClickListener(listener1);
    button2 = (Button) findViewById(R.id.activity_main_button2);
    button2.setOnClickListener(listener2);
    button3 = (Button) findViewById(R.id.activity_main_button3);
    button3.setOnClickListener(listener3);
    button4 = (Button) findViewById(R.id.activity_main_button4);
    button4.setOnClickListener(listener4);


  }
  private void prepareListeners(){
    listener1 = new OnClickListener() {
      public void onClick(View v) {
        Intent intent1 = new Intent(ActivityMain.this, ActivityList1.class);
        startActivity(intent1);
      }
    };
    listener2 = new OnClickListener() {
      public void onClick(View v) {
        Intent intent2 = new Intent(ActivityMain.this, ActivityList2.class);
        startActivity(intent2);

      }
    };
    
    listener3 = new OnClickListener() {
      public void onClick(View v) {
        Intent intent3 = new Intent(ActivityMain.this, ActivityList3.class);
        startActivity(intent3);

      }
    };
    
    listener4 = new OnClickListener() {
      public void onClick(View v) {
        Intent intent4 = new Intent(ActivityMain.this, ActivityList4.class);
        startActivity(intent4);

      }
    };

  }
}

   
    
    
    
  








Related examples in the same category

1.Using Intent to open other Activity
2.Create Intent to open a Uri
3.extends IntentService
4.Phone Intent
5.Map Intent
6.Market Intent
7.Load Activity with Intent
8.Using Intent to make another phone call
9.extends IntentService to create your own Intent
10.Adding data bundle to Intent
11.Start Intent with Utility class
12.Load library Activity with Intent
13.Capture Image with Intent
14.Intent.ACTION_MEDIA_MOUNTED
15.Using Intent to record audio
16.Video Player Intent
17.Video Capture Intent
18.Implementing an application service that will run in response to an alarm, allowing us to move long duration work out of an intent receiver.
19.Example of various Intent flags to modify the activity stack.
20.Sample code that invokes the speech recognition intent API.
21.extends IntentService to upload a file
22.factory class for generating various intents
23.Open Web Page Intent
24.Is Intent Available
25.start MMS Intent
26.Access the Internet
27.Pdf viewer
28.Rotation One Demo
29.Media activity