有谁知道如何在服务中获取 Edittext 值?

Does anyone know how to get Edittext value in service?

我想访问服务中的 EditText 值,但我不知道这样做的确切方法。我已经完成了这段代码。

Context context = getApplicationContext; 
Edittext et = (EditText)context.findViewById;

但它没有给我 findViewById 方法。

任何人都可以给我一些提示,告诉我如何访问服务中的 EditText 值。

first u need to bind the service,

in activity,you can get the service reference in the service connection. and pass EditText reference to service. and then set the text to it(check reff of edittext is null or not).

findViewById()View class 的方法,您不能在 Context 上调用它对象,尤其是在应用程序上下文中。因此,您需要在包含您的 EditText 的视图上调用 findViewById()。然后要获得输入的值,您可以在 EditText 上调用 getText() 并将此值作为 StringExtra 放入您的 Intent 如果您使用的是 IntentService 例如

以下代码可以帮助您在服务中获取 Edittext

context = getApplicationContext();
Activity a=(Activity)context;
EditText editText = (EditText)a.findViewById(R.id.editText1);