How to call class/activity from PreferenceActivity?



I have seen various questions online and here on "SO", but I am having a hard time trying to piece together the magic sequence of bits to launch an activity from inside my PreferenceActivity. I have a TimePickerDialog that is working fine if I wire it up to my options menu, but I think it would be ideal to have the dialog be launched and time set from inside the PreferenceActivity along with the other application settings. The application as it stands now, crashes after I select the intent preference item. I suspect the problem is inside my XML, but maybe one of you folks can figure it out. Here are the code bits:


XML:



<PreferenceCategory
android:title="Schedule E-mail"
android:key="checkprefs">
<SwitchPreference
android:defaultValue="true"
android:key="autosend"
android:title="System Notification"
android:summary="Send a system notification once a week.\n\nClick on notification to bring up a pre-populated E-mail for review to send."
/>
<ListPreference
android:key="dayOfWeek"
android:defaultValue="6"
android:title="Select day to send"
android:summary="Choose the day of the week to send the notification."
android:entries="@array/daysOfWeek"
android:entryValues="@array/daysOfWeekValues"
android:dialogTitle="@string/dialog_title_list_preference"
/>

<PreferenceScreen
android:title="Select Time (title)"
android:summary="Select Time (summary)"
android:key="time">

<intent android:targetClass="com.projects.app.sendvlog.TimePickerActivity"
android:targetPackage="com.projects.app.sendvlog"
android:action="android.intent.action.VIEW"/>

</PreferenceScreen>
</PreferenceCategory>


TimePickerActivity:



public class TimePickerActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_time_picker);
showTimePickerDialog();
}

public void showTimePickerDialog() {

DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getFragmentManager(), "timePicker");

}

}

No comments:

Post a Comment