Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:31:46+00:00 2026-05-26T05:31:46+00:00

Can you tell me why this click listener crashes the Android device when the

  • 0

Can you tell me why this click listener crashes the Android device when the user enters the settings screen?

    /*
     * Create the preference from the xml file. This will be used in a click
     * listener.
     */
    Preference settingWallpaperChangingIsActivated = (Preference)  findPreference("checkbox_change_wallpaper_is_activated");

    settingWallpaperChangingIsActivated
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                public boolean onPreferenceClick(Preference  preference) {
                    return true;
                }
            });

Here is the settings.xml file related to this click listener.

<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="@string/category_title_wallpaper">
    <CheckBoxPreference android:key="checkbox_change_wallpaper_is_activated"
        android:title="@string/item_title_change_wallpaper"   android:summary="@string/item_summary_change_wallpaper"
        android:defaultValue="false" />

    <ListPreference android:title="@string/list_title_time_before_changing_wallpaper"
        android:key="list_time_before_changing_wallpaper" android:summary="@string/list_summary_time_before_changing_wallpaper"
        android:entries="@array/label_time_before_changing_wallpaper"
        android:entryValues="@array/value_time_before_changing_wallpaper"
        android:defaultValue="Default" />

    <!-- -->
</PreferenceCategory>

</PreferenceScreen>

If the click listener is commented out than the settings screen can be displayed so it looks like there’s something wrong with the xml file or the click listener.

If I can get it to work, then I will put the additional coding before the return statement.

Thanks.

Truly,
Emad

Update:

This is the entire class that is now working thanks for everyone’s help:

import hajj.auto.wallpaper.R;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;

public class SettingsActivity extends PreferenceActivity implements
    OnSharedPreferenceChangeListener {

SharedPreferences pref;

/*
 * This is called when the class is created. It displays a Settings screen
 * from the settings.xml file.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*
     * Read the settings definition from XML and show them in the current
     * activity (screen).
     */
    addPreferencesFromResource(R.xml.settings);

    /*
     * This Preference Manager is required for the change listener to work.
     */
    pref = PreferenceManager.getDefaultSharedPreferences(this);

    /*
     * This will allow changes in lists to be trapped.
     */
    pref.registerOnSharedPreferenceChangeListener(this);

    /*
     * Create the preference from the xml file. This will be used in a click
     * listener.
     */

    CheckBoxPreference settingWallpaperChangingIsActivated = (CheckBoxPreference) findPreference("checkbox_changing_is_activated");

    //Preference settingWallpaperChangingIsActivated = (CheckBoxPreference) findPreference("checkbox_change_wallpaper_is_activated");

    settingWallpaperChangingIsActivated.setOnPreferenceChangeListener(new CheckBoxPreference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {

            Toast.makeText(getApplicationContext(), "Test.",
                    Toast.LENGTH_LONG).show();

            boolean activated = (Boolean) newValue;
           // updateStuff(activated);
            return true;


        }
    });


} // End method onCreate.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
        String key) {
    // TODO Auto-generated method stub

} // End method onSharedPreferenceChanged.

private void finishThisActivity() {
    this.finish();
} // End method finishThisActivity.
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:31:47+00:00Added an answer on May 26, 2026 at 5:31 am

    In the code, you’re using a Preference object, when in the XML you have a CheckBoxPreference. Those are two different things, and you can’t cast one to the other, if I recall correctly.

    Also, the appropriate listener that I think you are wanting is

    CheckBoxPreference.OnPreferenceChangeListener() {
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                // Your code here. Make good use of preference and newValue.
                // You can cast newValue to boolean, for example.
            }
    }
    

    Full working sample:

    Preference settingWallpaperChangingIsActivated = (CheckBoxPreference) findPreference("checkbox_change_wallpaper_is_activated");
    
    settingWallpaperChangingIsActivated.setOnPreferenceChangeListener(new CheckBoxPreference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
    
    
            boolean activated = (Boolean) newValue;
            updateStuff(activated);
            return true;
    
    
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody tell my why this doesn't work in the Android emulator? From the
Can someone tell me how to install this? I go here: http://api.jquery.com/browser/ and click
Can anyone tell me why this works: $(#test1 td).click(function(event) { $(#test1).addClass(tableRowSelected); }); $(#test2 td).click(function(event)
Can anyone tell me how this would look like in C#? <EventTrigger RoutedEvent=Button.Click SourceName=btnSplit>
From what I can tell from reading everything I can find here, this doesn't
Can anyone tell me why this coffee script: $ -> $('#btnLogin').live 'click', -> $.ajax
I can't tell if this is a result of the jQuery I'm using, but
Here is an example that a forum poster gave, I can't tell if this
Can someone tell me why this processes all the files and then does it
can anyone tell me why this does not work Excel.Worksheet ws_res = (Excel.Worksheet) wb.Worksheets.Add(mis,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.