user2712795
user2712795

Reputation: 65

change starting activity android

When I run my application, it starts up the activity_main.xml file instead of the login.xml file. When I go into my AndroidManifest, what do I change to make it so that the login file runs on start up? Thanks in advance! Here is the AndroidManifest:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dashboardactivity"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >


    <activity
        android:name="com.example.dashboardactivity.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
   </application>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name"
        android:name=".DashboardActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!--  Login Activity -->
    <activity
        android:label="Login Account"
        android:name=".LoginActivity"></activity>

    <!--  Register Activity -->
    <activity
        android:label="Register New Account"
        android:name=".RegisterActivity"></activity>
</application>

<!-- Allow to connect with internet -->
<uses-permission android:name="android.permission.INTERNET" />

NOTE:After editing the manifest looks like this:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dashboardactivity"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >


    <activity
        android:name="com.example.dashboardactivity.MainActivity"
        android:label="@string/app_name" >

    </activity>
   </application>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name"
        android:name=".DashboardActivity" >

    </activity>

    <!--  Login Activity -->
    <activity
        android:label="Login Account"
        android:name=".LoginActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!--  Register Activity -->
    <activity
        android:label="Register New Account"
        android:name=".RegisterActivity"></activity>
</application>

<!-- Allow to connect with internet -->
<uses-permission android:name="android.permission.INTERNET" />

When I run the app now, I get this error in the Console:

[2013-08-30 13:31:32 - DashboardActivity] Starting activity com.example.dashboardactivity.LoginActivity on device HT18YMA05067
[2013-08-30 13:31:32 - DashboardActivity] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.dashboardactivity/.LoginActivity }
[2013-08-30 13:31:32 - DashboardActivity] ActivityManager: Error type 3
[2013-08-30 13:31:32 - DashboardActivity] ActivityManager: Error: Activity class {com.example.dashboardactivity/com.example.dashboardactivity.LoginActivity} does not exist.

I have created a LoginActivity.java class so I don't know what's wrong.

Upvotes: 0

Views: 6754

Answers (3)

Mohit
Mohit

Reputation: 11324

this code causes for start activity

but it does not belong to xml file that are chosen by Activity Classes what ever xml (the layout file ) you have set in activity will be open.

add this code to that activity you want to start with but it must appear only once in manifest for only one activity

 <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

In your case

  <!--  Login Activity -->
    <activity
        android:label="Login Account"
        android:name=".LoginActivity">
   <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>

Upvotes: 0

pfairbairn
pfairbairn

Reputation: 451

You move

        <intent-filter >
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

To the activity you want to run first, in this case, login.

Upvotes: 0

codeMagic
codeMagic

Reputation: 44571

what do I change to make it so that the login file runs on start up?

You don't really change the xml file that is loaded, you change the Activity that is the Launcher. You do that in the <activity> tag of the Activity that you want to change. Like you have here

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

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

delete that Intent filter from that <activity> tag and add it to the LoginActivity

 <activity
    android:label="@string/app_name"
    android:name=".DashboardActivity" >
 </activity>

<!--  Login Activity -->
<activity
    android:label="Login Account"
    android:name=".LoginActivity"></activity>
   <intent-filter >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>

When I run my application, it starts up the activity_main.xml file instead of the login.xml file.

The layout.xml that is displayed is determined by what you use in your Activity in setContentView(). You could change that but that's probably not what you want. Its probably not just that you want a different layout but you want the LoginActivity to start when your app is opened and not the MainActivity.

Upvotes: 1

Related Questions