A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Launching an Activity from Preferences.
Joined: Jun 18, 2003
Jun 26, 2011 05:43:40
I have a PreferenceActivity Class that has the following code.
PreferenceScreen screen = (PreferenceScreen) findPreference(key); Intent intent = new Intent(this, MyActivity.class); screen.setIntent(intent);
Using this code, I am able to start MyActivity.
I want to know how to do this declaratively from the XML file inside PreferenceScreen tag. How to do it without writing code, there must be some way.
Joined: Mar 22, 2005
Jun 26, 2011 06:26:11
How to do it without writing code, there must be some way.
Why? The usual flow is to return to the previous activity after the preferences are done with. Starting some other activity is hardly a common use case.
Joined: Jun 18, 2003
Jun 26, 2011 19:56:05
Ok, here is the use case.
I have a preferences screen that has an option, which I click will list all the contacts.So this has to be done in an Activity I guess.
Also, in Google API Demos, there is an example that starts an activity from Preferences and that also declaratively using XML. The problem is, it is starting a browser that opens up www.android.com.
I want a declarative example how to declare intent tag that will be able to launch a normal Activity class.
Waiting for your response.
Joined: Jul 01, 2011
Jul 01, 2011 07:39:02
<PreferenceScreen android:title="@string/title_intent_preference" android:summary="@string/summary_intent_preference"> <intent android:action="android.intent.action.VIEW" android:data="http://www.android.com" /> </PreferenceScreen>
this is the example from that docs that you are referring to.
to start your activity you can do something like this
<PreferenceScreen android:title="@string/title_intent_preference" android:summary="@string/summary_intent_preference"> <intent android:action="your.action.string"/> </PreferenceScreen>
and you set an intent filter for that action
<activity ...> <intent-filter> <action android:name="your.action.string"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
It is sorta covered in the
JavaRanch Style Guide
subject: Launching an Activity from Preferences.
How to pic and cancel the in call programmetically on Android Version 5 (2.2) os .. replacement of-
how to make calls from SIP server?
Exiting from application
Availability of Intent
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015