English 中文(简体)
如何凌驾于甲状腺(String)法之中?
原标题:how to override toString() method in android service?

我试图推翻一项服务的职能。 我有一个服务,我正在利用另一个接见机。 然而,产出不是预期的,但我怀疑,压倒String(String)失败! 谁能帮助? 增 编

///////////////toString Function in the service !///////////////

public String toString() {
   return "Hello World";
}

//////////how I am calling the overridden function !////////////////////

ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);

List<ActivityManager.RunningServiceInfo> rs = am.getRunningServices(50);

for (int i=0; i<rs.size(); i++) {
    ActivityManager.RunningServiceInfo rsi = rs.get(i);
    Log.i("Hello",rsi.getClass().toString());
    Log.i("Service", "Process " + rsi.process + " with component " + 
            rsi.service.getClassName());
}
问题回答

You expect to have rsi.getClass().toString() return "Hello World" right? It doesn t work as expected above, because you call another toString method in another object. You call this function: http://developer.android.com/reference/java/lang/Class.html#toString()

Problem here is, that RunningServiceInfo only tells you about what Service is running. It doesn t actually give you the object of your service.

现在,你们如何能够纠正? 取决于你们想要做什么。

But the nicest way to access your service out of another application is to bind to it. If your Service is in the same app, you can follow this tutorial: http://www.androidcompetencycenter.com/2009/01/basics-of-android-part-iii-android-services/

How to do that out of another application:
how to bind a remote service that is installed on my android device?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签