0

As i am new to android programming, I don't know how to call a certain class and/or certain activity first.

For example i have two classes viz. 1) Login.java 2) Create.java and two xml files associated with them are activity_main.xml and create_new.xml respectively. So how can i make Login.java run first with activity_main.xml as screen?

Amit Anand
  • 1,225
  • 1
  • 16
  • 40

3 Answers3

1

from the intent filters you decalre in the android manifest file of your project;see the image You declare an intent filter in the activity tag something like shown in the image for making it the first activity of your application.and if there are other activities in your app having intent filters than you have to just change the capital letter MAIN to DEFAULT in the intent filter tag

enter image description here

You will find AndroidManifest file like in the following image in your projectenter image description here

nobalG
  • 4,544
  • 3
  • 34
  • 72
1

in login java use this

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);}

in create java us this

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create_new);

in androidmanifest

 <activity
        android:name=".Login"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

and another activities

   <activity android:name=".MainActivity" ></activity>
Asthme
  • 5,163
  • 6
  • 47
  • 65
1
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.your.package"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.your.package.activity.Login"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.your.package.activity.Create"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

In this case, the intent-filter of LOGIN activity specifies that the intent with action of MAIN and category of LAUNCHER will be caught by it, aka it is where the application starts.

Afterwards,

public class Login extends Activity
{
    //honestly I'd name this class LoginActivity and same in the XML
    @Override
    public void onCreate(Bundle saveInstanceState)
    {
        super.onCreate(saveInstanceState);
        setContentView(R.layout.activity_main);
    }

    ....
}

Also look at this example to learn how to use Fragments:

NullPointerException accessing views in onCreate()

Community
  • 1
  • 1
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
  • Here is a fragment "tutorial" project I pieced together: http://stackoverflow.com/questions/24840509/why-does-the-new-adt-create-a-static-inner-class-fragment-by-default-simple-fr – EpicPandaForce Jul 31 '14 at 06:35