当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to send text from Activity to WallpaperService class

问题描述:

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);
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: