+ Reply to Thread
Results 1 to 2 of 2

Thread: Using Intent in an Android application to show another activity

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    14

    Using Intent in an Android application to show another activity

    In my Android application, I have two activity classes. I have a button on the first one and I want to show the second when it is clicked, but I get an error. Here are the classes:
    Code:
    public class FirstActivity extends Activity {
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        Button orderButton = (Button)findViewById(R.id.order);
    
        orderButton.setOnClickListener(new View.OnClickListener() {
    
          @Override
          public void onClick(View view) {
            Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
            startActivity(intent);
          }
    
        });
      }
    }
    The second class that should show when the button is clicked, but never does:
    Code:
    public class OrderScreen extends Activity {
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order);
    
        Button orderButton = (Button) findViewById(R.id.end);
    
        orderButton.setOnClickListener(new View.OnClickListener() {
    
          @Override
          public void onClick(View view) {
            finish();
          }
    
        });
      }
    }
    How do I create a button that will show the second activity?

  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    12
    The issue was the OrderScreen activity wasn't added to the AndroidManifest.xml. Once I added that as an application node, it worked properly.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts