我想将文本从 MainActivity 发送到 WallpaperService 类以绘制文本。
主要 Activity 类-->
Intent in = new Intent();
in.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
in.putExtra("name", "sample text");
startActivity(in);
WallpaperService 类 -->
Bundle bundle = getIntent().getExtras();
String value = bundle.getString("key");
但是 WallpaperService 类中没有 getIntent() 方法。
最佳答案
1) 使用 Intent 中的 Bundle:
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(键,值)
新上下文(可以是 Activity/服务等)
Intent myIntent = getIntent(); // this getter is just for example purpose, can differ
if (myIntent !=null && myIntent.getExtras()!=null)
String value = myIntent.getExtras().getString(key);
}
关于android - 如何将文本从 Activity 发送到 WallpaperService 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23539277/