简体   繁体   中英

android manifest for activity starting within another activity

I am making an app in which i have a main activity that the user 'sees' on clicking the app icon and another activity which will be started by the user from within the main activity(by clicking the button on main activity screen) by using an intent. Now, how should i make the android manifest ? Should i nest the 2nd activity within the main activity or should i list it separately like the main activity ? Also when do we use an intent filter ? I searched on the web, some people have used an intent filter, others have not. My manifest file is given below. My app is starting but when i launch the 2nd activity, it stops working and asks for force close. Please help. And thanks for your time.

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

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/brain2"
        android:label="@string/app_name" >
        <activity
            android:name=".GraphsActivity" 
            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="MainPlot"></activity>


    </application>

</manifest>
Should i nest the 2nd activity within the main activity or should i list it separately like the main activity ?

both should come separately as flow of activity not effect manifest.

Also when do we use an intent filter ?

In your case only Setting Launcher activity intent filter needed which you have set.

My app is starting but when i launch the 2nd activity, it stops working and asks for force close.

use

<activity android:name=".MainPlot"></activity>

Even if you are calling second activity from first, for application, these are two independent activities, and you need to declare the second activity also like the first one.

An intentFilter is totally diff concept. Please read this for more info.

Use this

<activity android:name=".MainPlot"></activity>

And all activities you have to define separately not nested.

Yes, you need to use a intent filter

 <application
            android:icon="@drawable/brain2"
            android:label="@string/app_name" >
            <activity
                android:name=".GraphsActivity"
                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=".ClassName"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="com.Package.Name.CLASSSTART" />

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM