在學習的時候我們覺得建立新的項目很費時間,也費內存,所以我們很多時候都是在一個項目下面創建 多個activity來試驗
但是如何設置默認首先啟動的Avtivity 來驗證我們的新實驗是否成功呢?
在app.src.main下面有個Androidmanifest.xml 里面記錄了你項目有哪些activity 當然也記錄了那個是默認啟動項
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pro.first">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
</activity>
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".Main2Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我們直接將下面這段代碼放在你想默認啟動的activity中間就行了 就像上面的代碼 默認首先啟動的是main2activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
