-2

I made an android app but I wanted to start a new activity (.xml). Normally when an app starts it shows direct the activity_main.xml layout file. I don't know how that is going on so what's the code for this because so I know how to start a new activity.

Kara
  • 6,115
  • 16
  • 50
  • 57
r_benjamin
  • 53
  • 7

3 Answers3

0

You can specify the layout you want to show in your Activity using setContentView method:

setContentView(R.layout.layoutForYourActivity);

This has to be specified inside your onCreate method

Luciano Rodríguez
  • 2,239
  • 3
  • 19
  • 32
0

Simple u have need in main activity :-

 {
(R.layout.main_activity);
   Intent intent =new Intent(getApplicationContext(),AnotherActivity.class);
   startActivity(intent);
 }  
and then you have create `AnotherActivity.class
and insert another layout for AnotherActivity in (R.layout.anotherlayout);
that solve 
Amitsharma
  • 1,577
  • 1
  • 17
  • 29
0

Create a new activity through New -> Other -> Android -> Android Activity

A activity is a .java file, the .xml is only the layout. Call the new activity with

intent = new Intent(main.this, YourActivity.class);
startActivity(intent);

I suggest you to do some basic tutorials.

Krystex
  • 147
  • 1
  • 8