Android Developer, Only one class is Launched

80 views Asked by At

So I am making a test app and added 3 extra classes with a corresponding .xml file. Each class extends Activity and are referred to in the .Manifest file as an activity . In the Manifest the Main class is set to LAUNCHER and the rest of the classes are set to DEFAULT. However when I play the APP only the Main class is launched and the rest are just "ignored" . This also got me think , how are the classes arranged in order(i.e. how to make sure that class1 launches before class2) I am new to this , so sorry if there is an obvious answer.I thank you in advanced for your answers

3

There are 3 answers

0
NightWatcher On

You need to create Intent from your first activity to start other activity. .Manifest file will launch one activity only. Others you need to start using Intent

0
Kristy Welsh On

In your Main Activity, you need to create a clickable button that will launch your second and third activities.

class MainActivity extends Activity { 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.yourlayout);
    Button button = (Button) findViewById(R.id.yourbutton);


    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

        Intent startNewActivityOpen = new Intent(MainActivity.this, SecondActivity.class);
        startActivity(startNewActivityOpen);
        finish();
        }
    });

   }
}
0
Manuel de Oca On

Your App will only launch the main activity that has the LAUNCHER and MAIN in the Intent filter in your manifest file. Like this:

<activity android:name="MainActivity">
    <!-- This activity is the main entry, should appear in app launcher -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

any aditional activities that you want to launch you will need to create an Intent that is linked to that activities class file, and then call the startActivity method. Like this :

Intent newActivtyIntent= new Intent(this, newActivty.class);
startActivity(newActivtyIntent);

Hope this helps.