Start custom Activity from PreferenceActivity via xml intent and getResult back

hbkana2ran

New Member
this is my first post on stackoverflow and I would like to thank you all for your work. It helped me a lot in learning how to code in the past.I'm relatively new to Java, object orientated programing and especially Android. (Just programmed C and vhdl for about 10 years.) So if I was just blind to find the answer by myself, forgive me. I'm stuck since over 10 hours of trying and googling now, so I hope you can help me.I have set up a PreferenceActivity with fragments which is fed from xml files. This is working very well. I use an intent-filter via xml as shown below to start my own activity. This activity is well tested and returns a string via .putExtra. (Tested in the Main Activity with startActivityForResult() and onActivityResult() ) My custom activity is triggered when I click on the preference entry and the return to the PreferenceActivity also workes, but I have no idea how to catch that result in my PreferenceActivity.My first thought was to use onActivityResult() in MyPreferenceFragment which didn't work at all. It was never executed I tried it via getIntent in onResume() which crashed my application and isn't a nice approach at all i think.I will have to use ListActivity a few times in the preferences so I have to keep it generic and handle the destination of the result in the parent activity. (Most of it is the DeviceListActivity from the android bluetooth example which returns a device address.) Could anybody give me a hint how to do that?Thank you a lot\[code\]public class AppPreferenceActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle("Settings"); } @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.preference_headers, target); } public static class MyPreferenceFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.my_settings_preferences); } }}\[/code\]my_settings_preferences.xml (most of it)\[code\]<PreferenceCategory android:title="@string/devid_title" > <PreferenceScreen android:key="device_ID" android:summary="@string/devid_summary" android:title="@string/devid_title" > <intent android:action="com.xxx.getxy_id" > <extra android:name="getbodytel_id" android:value="http://stackoverflow.com/questions/11427971/1" /> </intent> </PreferenceScreen></PreferenceCategory>\[/code\]Manifest.xml (relevant parts)\[code\]<activity android:name=".ListActivity" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Holo.Dialog" > <intent-filter> <action android:name="com.xxx.getxy_id" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter></activity>\[/code\]
 
Back
Top