简体   繁体   中英

Starting Activity from the Preference Screen in XML?

The Activity I want to start is defined in my androidmanifest.xml like so:

<activity
    android:name="about"
    android:label=""
    android:configChanges="orientation"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="com.nick.simplequiz.paid.ABOUT" />

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

And this is how I attempt to call it from my preference screen:

<Preference android:title="About"
    android:key="about">
    <intent android:action="com.nick.simplequiz.paid.ABOUT"/>
</Preference>

When the app runs and I click on the preference, it doesn't actually appear to open the Activity. It just closes the settings preference Activity. What is the correct way to accomplish this?

Your problem that the activity name is case-sensitive so you need to use the same naming in the class name, manifest and preferences xml

Also the activity name should be preceeded by a "." or to give it a path yourpackage.path.to.activity

<!--Manifest Example-->
        <activity
            android:name="com.nick.simplequiz.paid.ABOUT"
            android:label=""
            android:configChanges="orientation"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="com.nick.simplequiz.paid.ABOUT" />

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

    <!--XML example-->
    <Preference android:title="About"
        android:key="about">

        <intent android:action="com.nick.simplequiz.paid.ABOUT"/>

    </Preference>

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