Change application's starting activity

前端 未结 11 2024
温柔的废话
温柔的废话 2020-11-22 16:51

I have created the meat and guts of my application but I want to add a different activity that will be the starting point (sort of a log-in screen).

Couple questions

相关标签:
11条回答
  • 2020-11-22 17:22
     <application
        android:icon="@drawable/YOUR_ICON"    <!-- THIS ICON(IMAGE) WILL BE SHOWN IN YOUR APPS -->
        android:label="MY APP NAME " >    <!-- HERE LABEL(APP NAME) -->
        <activity
            android:name=".application's starting activity"  <!-- (.)dot means current dir, if your activity is in another package then give full package name ex: com.xxx.Activity  -->
            android:label="LABEL FOR ACTIVITY "
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
    0 讨论(0)
  • 2020-11-22 17:25

    Yes, you use the AndroidManifest.xml file. You can actually even have more than one launcher activity specified in your application manifest. To make an activity seen on the launcher you add these attributes to your activity in the manifest:

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    
    0 讨论(0)
  • 2020-11-22 17:34

    In a recent project I changed the default activity in AndroidManifest.xml with:

    <activity android:name=".MyAppRuntimePermissions">
    </activity>
    
    <activity android:name=".MyAppDisplay">
        <intent-filter>
            <action android:name="android.intent.activity.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    In Android Studio 3.6; this seems to broken. I've used this technique in example applications, but when I use it in this real-world application it falls flat. The IDE once again reports:

    Error running app: Default activity not found.

    The IDE still showed a configuration error in the "run app" space in the toolbar (yellow arrow in this screenshot)

    To correct this error I've tried several rebuilds of the project, and finally File >> "Invalidate Cache/Restart". This did not help. To run the application I had to "Edit Configurations" and point at the specific activity instead of the default activity:

    0 讨论(0)
  • 2020-11-22 17:37

    It's simple. Do this, in your Manifest file.

    <activity
        android:name="Your app name"
        android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
    </activity>
    
    0 讨论(0)
  • 2020-11-22 17:38

    This is easy to fix.

    • Changes to the Launcher activity are also stored in the Debug configuration.
    • Go to Run > Debug Configurations and edit the setting.
    • There is also a similar setting in Intellij under Run > Edit Configurations select Run default Activity and it will no longer save the setting in this fashion.
    0 讨论(0)
  • 2020-11-22 17:38

    Just go to your AndroidManifest.xml file and add like below

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

    then save and run your android project.

    0 讨论(0)
提交回复
热议问题