Start activity from preference-headers

帅比萌擦擦* 提交于 2019-12-01 03:54:30

If you want to start an explicit Activity from your third preference then do this:

<intent android:targetPackage="com.mycompany.myapp"
        android:targetClass="com.mycompany.myapp.ui.MyPreferenceActivity" />
 <header android:title="Intent"
    android:summary="Launches an Intent.">
<intent android:targetPackage="com.mycompany.myapp"
        android:targetClass="com.mycompany.myapp.ui.MyPreferenceActivity" /></header>

and add the below code in mainfest file

<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>

if you are creating preferences using java ,then you can achieve the same result by,

PreferenceScreen editPhoneNumbersScreen = getPreferenceManager().createPreferenceScreen(mContext);
    editPhoneNumbersScreen.setTitle(getResources().getString(R.string.change_add_emergency_numbers));
    editPhoneNumbersScreen.setSummary(getResources().getString(R.string.summary_add_no));


 Intent i = new Intent(getApplicationContext(),TargetActivity.class);
i.putExtra("change numbers", true);
        editPhoneNumbersScreen.setIntent(i);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!