2

I have a test live wallpaper that I wish to start from an activity. At the moment, it immediately finds itself in the live wallpaper chooser as I run the project on my emulator. Having searched everywhere, I still can't find a way to make it show up there only after a button in my main activity is pressed.

I tried introducing a static boolean in my main activity, isnotpressed, and setting it to false in the button onClick(). Then I used stopSelf() in my wallpaperservice class while isnotpressed is true. Unfortunately, none of this was to any avail and I don't think I'm going about it in the right way anyway. I also tried this, but it didn't work either. Any help would be deeply appreciated here.

Here's the main activity:

public class TestProjectActivity extends Activity{

static boolean isnotPressed;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    isnotPressed = true;

final Button b1 = (Button) findViewById(R.id.button1);

b1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        isnotPressed = false;
    }
});

}

}

And here's part of the wallpaperservice:

public class MyWallpaperService extends WallpaperService {




@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();

    while(TestProjectActivity.isnotPressed){stopSelf();}


}
Community
  • 1
  • 1

1 Answers1

0

Try this :

    Intent i = new Intent();
    if (Build.VERSION.SDK_INT > 15)
    {
        i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
        String pkg = MyPreferencesActivity.class.getPackage().getName();
        String cls = MyPreferencesActivity.class.getCanonicalName();
        i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(pkg, cls));
    }
    else
    {
        i.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
    }
    startActivityForResult(i, 0);
DearDhruv
  • 778
  • 13
  • 34