开发者

How to change the startup activity in android?

开发者 https://www.devze.com 2023-03-16 01:16 出处:网络
I have two activities namely login an开发者_StackOverflowd calendar in my Application. Currently my startup activity is \"calendar\". I want to run the login as first activity not calendar.The startup

I have two activities namely login an开发者_StackOverflowd calendar in my Application. Currently my startup activity is "calendar". I want to run the login as first activity not calendar.


The startup activity [Launcher Activity] is declared in the projects' AndroidManifest.xml file

Look for that activity tag in the manifest which looks like this

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

Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.

That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.


Add Intent filter to the Activity in which you want startup. In your case Modify the AndroidManifest.xml file as follows

<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>


remove the intent-filter code from calendar Activity tag in manifest and add it to the Activity you wanna load first

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

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

I mean paste it in the activity you like to run as default.

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

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

Where as

From the docs

category -- Gives additional information about the action to execute. For example, 

CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while 

CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can 

perform on a piece of data.

MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.


You want the Application element of the Android Manifest file. You can see details here. Look at the name attribute, this points to the Application class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号