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 7175907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:23:57+00:00 2026-05-28T16:23:57+00:00

I do wallpapers to andoid and I want that the user could choose options.

  • 0

I do wallpapers to andoid and I want that the user could choose options. Menu with options is showed but it have problem. When i click any options and go back to wallpapers screen, they dont update with new options. Why?
My code WallpaperService:

public MyWallpaperEngine(WallpaperService ws)
    {
        context = ws;
        prefs = LiveWallpaperService.this.getSharedPreferences(SHARED_PREFS_NAME, 0);

        OnSharedPreferenceChangeListener listener 
        = new SharedPreferences.OnSharedPreferenceChangeListener() {
            public void onSharedPreferenceChanged(SharedPreferences prefs, String key)
            {
                if(key != null){
                    if(key.equals("BACKREPEAT")){
                        if(BACKREPEAT)
                            BACKREPEAT = false;
                        else
                            BACKREPEAT = true;
                    }
                }
            }
        };
        prefs.registerOnSharedPreferenceChangeListener(listener);

        handler.post(drawRunner);
    }

upd:
I have made, as was written in an example, but the result hasn’t changed..
LiveWallpaperService code:

package com.samples;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.SurfaceHolder;

public class LiveWallpaperService extends WallpaperService
{
    public static final String SHARED_PREFS_NAME = "leoSettings01";

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public Engine onCreateEngine() {
        return new MyWallpaperEngine();
    }

    private class MyWallpaperEngine extends Engine implements 
    SharedPreferences.OnSharedPreferenceChangeListener {

        private final Handler handler = new Handler();

        int draw_x = 0;
        int draw_y = 0;
        //...

        boolean BACKREPEAT = false;

        private final Runnable drawRunner = new Runnable() {
            @Override
            public void run()
            {
                draw();
            }
        };

        private boolean visible = true;
        private SharedPreferences prefs;

        MyWallpaperEngine()
        {
            prefs = LiveWallpaperService.this.getSharedPreferences(SHARED_PREFS_NAME, 0);

            prefs.registerOnSharedPreferenceChangeListener(this);
            onSharedPreferenceChanged(prefs, null);

            handler.post(drawRunner);
        }
        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
            if(key != null)
            {
                Log.v("key:", key); //no message!

                if(key.equals("BACKREPEAT")){
                    if(BACKREPEAT)
                        BACKREPEAT = false;
                    else
                        BACKREPEAT = true;
                }
            }
        }
        @Override
        public void onVisibilityChanged(boolean visible) {
            this.visible = visible;
            if (visible) {
            handler.post(drawRunner);
            } else {
            handler.removeCallbacks(drawRunner);
            }
        }
        @Override
        public void onSurfaceDestroyed(SurfaceHolder holder) {
            super.onSurfaceDestroyed(holder);
            this.visible = false;
            handler.removeCallbacks(drawRunner);
        }

        private void draw()
        {
            SurfaceHolder holder = getSurfaceHolder();
            Canvas canvas = null;

            try
            {
                canvas = holder.lockCanvas();
                //...draw draw draw
            }
            finally
            {
                if (canvas != null)
                        holder.unlockCanvasAndPost(canvas);
            }
            handler.removeCallbacks(drawRunner);
            if (visible)
            {
                handler.postDelayed(drawRunner, DELAY);
            }
        }   
    }
}

prefs.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        <PreferenceCategory android:title="General">
                <CheckBoxPreference
                        android:title="Animation repeat"
                        android:key="BACKREPEAT" 
                        android:defaultValue="false"
                />
        </PreferenceCategory>
</PreferenceScreen>
  • 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-28T16:23:58+00:00Added an answer on May 28, 2026 at 4:23 pm

    Your wallpaper will never restart after coming back from settings. The only method invoked will be your Engine’s onVisibilityChanged. If your correctly implements SharedPreferences.OnSharedPreferenceChangeListener on your Engine, then onSharedPreferenceChanged should be called too.

    Please check if you implemented OnSharedPreferenceChangeListener exactly this way:
    http://developer.android.com/resources/samples/CubeLiveWallpaper/src/com/example/android/livecubes/cube2/CubeWallpaper2.html

    If you did and it is still not working, please post your entire WallpaperService and settings preference activity code here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I want to create an Android App which captures
I have two Live Wallpapers that belong to the same Application and I am
I have a custom image preference in my Live Wallpaper that allows a user
So, I have application, there is profile in there. I want to add menu
I have the following HTML statement [otsection]Wallpapers[/otsection] WALLPAPERS GO HERE [otsection]Videos[/otsection] VIDEOS GO HERE
I'm writing an app and I want one of my activities to have a
Alright, so, I'm doing a little script that downloads X number of wallpapers of
I have a ViewPager in which I change images with swype. Now I want
I'm making a Live wallpaper for Android, and I want it scroll as user
I have noticed that some Android applications adds a new Wallpaper-gallery to the Wallpaper-chooser.

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.