jhc
jhc

Reputation: 1769

What is the best way to switch Android Activities?


I have been developing a map app for Android. Initially I intended to make the main screen the map itself. After discussion with my boss, it has been decided that I make a normal (non-map) layout as my first screen and then have a button to access that map.

I have the first screen ready to be used. The name of this activity is LocateActivty.java. The name of the map activity is MainActivity.java. Since I initially developed the map activity first, it obviously continues to be opened as the first screen.

What changes should I make to the files (if any) and to any configuration files to make LocateActivity.java my main activity?

EDIT - Manifest code

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.aquamet.saramap.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>

    <activity
        android:name="com.aquamet.saramap.LocateActivity"
        android:label="@string/title_activity_locate"
        android:parentActivityName="com.aquamet.sara.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.aquamet.sara.MainActivity" />
    </activity>
</application>

Upvotes: 1

Views: 167

Answers (1)

Matt Taylor
Matt Taylor

Reputation: 3408

The lines of XML in the manifest:

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

Need to be moved from the Activity tags for MainActivity, and put inside the tags for LocateActivity. This will then mean that LocateActivity receives the Launcher intent when the user opens your application

Upvotes: 3

Related Questions