3

I want to send text from MainActivity to WallpaperService class to draw Text.

Main Activity class-->

Intent in = new Intent();


    in.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
                in.putExtra("name", "sample text");
                startActivity(in);

WallpaperService class -->

Bundle bundle = getIntent().getExtras();
        String value = bundle.getString("key");

But the getIntent() method is not available in WallpaperService class.

abhi
  • 154
  • 16

1 Answers1

-1

1) Use the Bundle from the Intent:
Intent mIntent = new Intent(this, Example.class); Bundle extras = mIntent.getExtras(); extras.putString(key, value)

New Context (can be Activity/Service etc)

 Intent myIntent = getIntent(); // this getter is just for example purpose, can differ
if (myIntent !=null && myIntent.getExtras()!=null)
     String value = myIntent.getExtras().getString(key);
}
  • Where its is showing null pointer error can you post some code so that can get a better idea for the same – user3519641 May 09 '14 at 07:29
  • The below code is in Main Activity class and showing null pointer exception in last line. Intent mIntent = new Intent(SetWallpaperActivity.this, LiveWallpaperService.class); Bundle extras = mIntent.getExtras(); extras.putString("name", "sample"); – abhi May 09 '14 at 08:10