问题描述:

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.

网友答案:

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);
}
相关阅读:
Top