Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

start a remote service and receive a result in Android

I have two applications. One app has the Activity and another one is a background service.

I can able to access the service app from my activity app using implicit intent filters.

I need to receive a result from the service.

For ex:

From activity app, i am going to start the service and send a data. In the service app, i need to receive the data and do some inspections and need to return to the activity app as modified result.

I can able to send by putExtra and can able to retrieve it in the service by getExtra. I need to return a value from service and receive it in activity app.

PS: The thing i needed is, the same way what we do with finish() and onActivityResult() with the Activity results.

Thanks in advance to you masters...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First add a class like this:

package com.test.context; //For example
public class MyContext extends Application
{
   //Here you define the attributes to share through the application
   // with setters and getters
}

and in the AndroidManifest.xml, add the path of the class, in the example is com.test.context so:

<application android:name="com.test.context.MyContext"
                 android:icon="@drawable/ic_launcher"
                 android:label="@string/app_name">

Then in your code you can do some like this:

MyContext ctx = (MyContext)getApplication();

And you will be able to share data in all the app, btw activities and services, i did it this way in a Tasker , and works fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...