搜尋此網誌

2017年6月22日 星期四

【Android】Start Activity from preference screen (intent defined in xml file)

ref:https://stackoverflow.com/a/16943447
https://stackoverflow.com/a/10441707
https://stackoverflow.com/a/15288147


Preferences xml
<PreferenceCategory
        android:title="@string/my_activity_title">
    <PreferenceScreen
        android:title="@string/my_activity_title" 
        android:summary="@string/my_activity_title">
        <intent android:action="com.example.myapp.activities.MyActivity">
                <extra android:name="extra_name" android:value="my_value" />
        </Intent>
    </PreferenceScreen>
</PreferenceCategory>  
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.myapp" android:versionName="1.3" android:versionCode="4">

...

    <activity android:name=".activities.MyActivity" 
              android:label="@string/my_activity_title"
              android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
           <action android:name="com.example.myapp.activities.MyActivity" />
           <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>
    </activity>
MyActivity.java

getIntent().getStringExtra("extra_name") ....

沒有留言: