Android :: Remote Service Returning Value From Http Transaction

May 6, 2009

I've been researching how to best implement a service which performs a network transaction and returns data to the caller.

Clearly, this needs to happen on its own thread which means some form of async response. I can see at least three ways of doing this--some more complex than others. In the descriptions below, C is the caller, S is the service.

1) C wraps a Handler in a Messenger object, adds this to an Intent. C then calls startService with this intent. S extends IntentService which runs the Intents received in a worker thread. S then sends a message to C via the Messenger. This has the benefit of not requiring any of the async binding process or making an IDL interface that needs to be compiled into C. This seems to be the closes to a Handler-based response mechanism of Local Services.

2) C binds to S and then uses AsyncTask<> to make a blocking call to S. S performs the network transaction and returns the data in the return value or an out parameter. This requires the async binding process, but does not require a callback function since the inter- thread communications is handled by AsyncTask<> and the worker thread is in C's context.

3) Make the function called in S be completely asynchronous. S defines two interfaces: IMyService and IMyServiceCallback. S implements IMyService.Stub. C implements IMyServiceCallback.Stub. C binds to S then calls S via IMyService, passing its IMyServiceCallback binder. S spins up a worker thread and returns immediately. S then calls the callback when it has completed the network transaction.

I am asking for advice on which methods are most appropriate. I do not need the the service running constantly, only when the web transaction is required. C does not use S all the time--definitely don't want to bind during C's onCreate. However, I would like the time from when C determines it needs to use S to getting the results back to be as quick as possible (i.e. adding minimal latency to the already latent network access).

Is there any preference to having the worker thread in C or in S? Are there any significant problems with option 1?

Android :: remote service returning value from http transaction


Android :: Failed Binder Transaction When Returning Camera Image

Feb 15, 2010

I get the Failed binder transaction error in the logcat when returning the image taken with the camera from the camera intent back to the parent intent (as a byte[] using putExtra). I don't understand why, its not like its a big bitmap or anything. It only happens when i take pictures with lots of light, because then the byte[] is bigger. The error occurs when leaving the camera intent. Does anyone see a mistake in my code?

Here is the code of the camera intent:

CODE:.............

And here is the code that calls the camera intent:

CODE:..................

View 1 Replies View Related

Android :: Returning From HTTP Intent.ACTION_VIEW

Mar 23, 2009

I have an application that needs to have a user visit a web page to authorize it. After spending time in the Browser the user should return the my application.

Currently, I'm launching the Browser with:

CODE:................

After using the browser, I can go back home and launch my application, which stacks a new Activity on top of the previous stack of Activities that were being used in the application. For example. If the user launches the app, they have Activity A in the stack. From there we navigate to Activity B which then launches the Browser. Then, the next time we enter the app, we launch Activity A, which is pushed onto the stack that already contains an A and B.

My question is then, how can I just go back to the previous stack? Basically, do I have to create a new Activity? Is there a better way to launch the Browser, and then come back to my application?

Also, I've been using the Intent.FLAG_ACTIVITY_NEW_TASK when I start the Browser activity so that my app stays running.

View 2 Replies View Related

Android :: Http Post Abort Not Returning Immediately When Called From Separate Thread

Mar 24, 2010

I am using a DefaultHttpClient and a ThreadSafeClientConnManager to share the httpClient across threads. That part is working well. However, when I execute an HttpPost in one thread, and call httpPost.abort() from another. It does not return immediately and continues blocking until the socket timeout is reached in most cases. Am I missing something else? I've tried using: connectionManager.closeIdleConnections(30, TimeUnit.SECONDS); connectionManager.closeExpiredConnections();

View 2 Replies View Related

Android :: Returning An XML File From Web Service To Device

Aug 10, 2010

I have a set of mp3 files on my computer which i want to be the server. Now i have a web service(Songs_Collection). This web service returns the list of all songs present on the server to the user.The user can download the desired file directly from the server.

I have a small problem :

How does my web service get the list of audio files kept on the server in the folder c:Audio Files.

Someone suggested that i need to keep the names in a "Web Content" folder, but can anyone suggest how should i approach it?

I worked out on this part . But now how do I send it to the client on device ?

Can i send it directly as an array? I guess then some seriliazation-deserialization needs to be done. Or If send it as an XML file then how should I proceed? (This is more important)

View 1 Replies View Related

Android :: Playing Audio Or Video From Remote URL - RTSP/HTTP

Nov 4, 2009

Did anyone try playing audio/video through http/rtsp. I am having a problem with either of the approach.... I am getting an error Command PLAYER_INIT completed with PVMFError I some cases I got Command PLAYER_INIT completed with PVMFErrorContentInvalidForProgressiveDownoload.

Can some one explain what is the problem. The code snippet I am using is given below. Code...

The code works fine when I say mVideoView.setVideoPath("/sdcard/vv.3gp"); but not able to play if I give a rtsp/http urls. In case of http it says PVMFErrorContentInvalid for progressive download.

Can some body tell me what is the problem. Can you please post the code if someone has been successful in playing audio/video through http/rtsp.

View 8 Replies View Related

Android :: Play Video From Remote URL - Getting - Http Request Failed 404

Nov 18, 2010

I am New to android my intention is to play video using Http. But i am "Http Request Failed 404" Exception when iam trying to run my application in emulator.
can any one know this error?

View 3 Replies View Related

Android :: Local Service Vs Remote Service

Nov 9, 2010

I'm confused about whether I need to run my service in a separate process. What are the advantages / disadvantages of each?For reference I'm trying to create an App that uses a service to play [streaming] audio in the background. So which one is better for my use case?

View 1 Replies View Related

Android :: Does Service Have To Be Remote Service Or Can It Still Be Local?

Sep 30, 2009

i have an app that binds to a local service.I want to add a desktop widget that binds to the same service. does my service have to be a remote service or can it still be local?if it can still be local, how can I get at the local binder?

View 2 Replies View Related

Android :: Android Remote Service Doesn't Call Service Methods

May 28, 2010

I'm developing a GPS tracking software on android. I need IPC to control the service from different activities. So I decide to develop a remote service with AIDL.This wasn't a big problem but now it's always running into the methods of the interface and not into those of my service class. Maybe someone could help me?If i now try to call a method from an activity for example start(trackId) nothing happens. The binding is OK. When debugging it always runs into the startTracking() in the generated ITrackingServiceRemote.java file and not into my TrackingService class. Where is the problem? I can't find anything wrong.

View 1 Replies View Related

Android :: Can't Do A HTTP Post To A Web Service From My App

Sep 8, 2010

I've been working on an app that uses both GET and POST requests to Web Services. The GET requests are no problems but the POST requests are killing me. I've tried 2 different scenarios in the code. The first looks like this...

CODE:......

This code gets this result for me..."Bad Request (Invalid Header Name)"

Now here's my second piece of code...

CODE:.....

This gives me an entirely different result. It's a long garbled mess of xml and SOAP that does have a SOAP Exception mentioned in it..."Server was unable to process request. --- System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1." Now, can anyone shed any light on what I am doing wrong.

View 1 Replies View Related

Android :: Whether To Use Service Or Thread For Http Connection?

Jul 5, 2010

I am a newbie in android and i had a question whether i should use a service or thread for http connection and what will be the advantage of using a service over a thread or viceversa. Please help me out with this.

View 13 Replies View Related

Android :: Using Remote Service From Other App

Sep 24, 2009

I've implemented remote service using aidl & it is working fine if I'm using its service from same package. But If I tried to use the service from other application it gives me error

As below:

CODE:...................

View 3 Replies View Related

Android :: HTTP Post Works In Activity But Not In Service

Nov 5, 2010

GI am trying to do a http post to a php script. the method works if I place it in the onCreate event of the application but gets a ConnectionTimeOut error when it tries to execute it from the service.

Here is an example of my method

CODE:...................

I have no idea why the service would get a time out error but the application activity would not.

View 5 Replies View Related

Android :: Saving CookieStore In Http Client Service

Feb 9, 2010

I have a Service for my Android app that performs HTTP calls. The Service stores cookies in a CookieStore. I am trying to find a way to persist the CookieStore but I haven't been successful. I don't want the user to log in every time to receive a new CookieStore.

I tried to use SharedPreferences to store the CookieStore as a string, but I can't re-construct the CookieStore with a String.

Has anyone else had success in persisting a CookieStore?

View 1 Replies View Related

Android :: API Demo Remote Service Example

Sep 22, 2009

I am studying RemoteService example in Android's APISample. In the manifest file, it declares the service like this: My question is how can I specify the service to be 'auto-start', i.e. it gets start whenever the phone start?

<service android:name=".app.RemoteService" android:process=":remote" >
<intent-filter>
<!-- These are the interfaces supported by the service, which
you can bind to. -->
<action

android:name="com.example.android.apis.app.IRemoteService" />

View 1 Replies View Related

Android :: Remote Service - Reconnecting

Aug 11, 2010

I have implemented a RemoteService which will increment a countere ( just for testing purposes ). Therefore I have a Task class which implements Runnable and the method run() where a infinite while loop increments the variable.

From the client side, I start the RemoteService with startService and then i bind to the service. When I close the activity, the service is still running. Now i want to rebind to the service.

How do I know if the service has already been started (therefore i would only need to bind to the service again) or not (then I would need to call startService() first and then bind to the service)?

What would happen, if I call startService() if the service is already running? Does the OS start a second service, or will it affect the service which is already running?

View 5 Replies View Related

Android :: How To Execute A Remote Service

Jul 28, 2010

I have a service MyService.java in Application "ServiceDemo". The manifest of this application looks like this

CODE:.............

I have another application "CallerService" manifest looks like this

CODE:................

I have an activity from where I m trying to start the service on the click of the button

CODE:................

This fails to work. Says "unable to start service intent"

View 1 Replies View Related

Android :: Activity Starts Remote Service

Oct 8, 2010

My initial activity is basically a splash screen while preforming initialization and login in to network server. To save memory I want to finish() the splash activity once it starts the main menu activity. I still want the remote service to operate. Testing shows it does. But am I going to get into trouble doing this? I know I can restart the remote from the main menu activity but I am trying to save overhead by not starting it twice. The remote service is required by the splash activity.

View 1 Replies View Related

Android :: Access Remote Service In Different Application

Apr 30, 2010

I defined a remote service over a AIDL file. Now i want to access this service in a different application. But how can I do that? The AIDL file is not accessible in my second application, and if i just copy the AIDL file, then the service can't be found.

View 1 Replies View Related

Android :: Broadcast Receiver And Remote Service

Jan 20, 2010

I'm hoping to do some audio processing in a remote service (service I've spawned onto its own thread); this will basically occur in a while (1) loop so constant processing. Occasionally I want to provide some information back to the activity that is bound to the service; I'm doing this by sending a broadcast from the service, that is received by a broadcast receiver on the activity, which then uses the activity's service connection to call into the service and get the information needed; at this point the broadcast receiver makes an alert dialog presenting the information to the user.If I stay in my while(1) loop after raising the broadcast, the action in the broadcast receiver never seems to occur.This is confusing to me since the activity and service are in separate threads.If I end the loop after raising the broadcast, the desired behavior on the activity side occurs, but of course this isn't acceptable since I need to be doing constant processing.

View 11 Replies View Related

Android :: Does Use Of A Remote Service Help Avoiding GC Lags

May 18, 2010

Since yesterday I got an idea running around my mind but I donīt know first if it would work, and then how "hack" it would be.

People who develop audio processing/recording/playback apps for Android know how hard it is to maintain GC away from our critical paths: playing and recording audio. Processing must be as optimized as possible not only to save battery and use less CPU, but also not to create new objects/allocate new memory spaces ... this all to avoid GC at all cost. Well, we have knowledge and this we can handle (mostly). But what about all the other processing that happens from and for user interaction? Media players display images, some apps display ads, ... and sometimes we have to avoid releasing features to the users just to maintain our critical paths free from GC.

Yesterday I stumbled upon an article about remote services and this led me to a doubt: if they can run as a different process, would a GC call from my activity impact the performance of my remote service? I really donīt know how GC works on the Dalvik so this may be a dumb question. If so, I apologize.

You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

View 4 Replies View Related

Android :: Provide Sample Remote Service Example?

May 6, 2010

Can any one provide sample Remote service example. I want it like two different application. One application should contain service. Another application should use that service.
Thanks in adv....

View 1 Replies View Related

Android :: Binding A Remote Service From An Activity

Nov 23, 2009

I am binding a remote service from an activity and unbind the same on the onPause of the Activity,when the activity again restarts i bind the service .It does bind with the remote service and i am also successful in getting the remote-service method getting executed after the restart.But when returning a message from the callback-RemoteCallbackList.the mCallbacks.beginBroadcast returns me 0 clients.Am i missing some thing here ?why am i am getting zero clients when I call mCallbacks.beginBroadcast.?

CODE:....................

View 2 Replies View Related

Android :: Services - Remote Service - Diffrence?

Apr 21, 2010

"Service" by it's defenision meaning the same as "Remote service" in Android? and if not, what is the diffrence between them?

View 1 Replies View Related

Android :: Step Through Code In Remote Service

Aug 15, 2009

Is there a way to step through code in a remote service? What I do now is install the service, then run the app that starts it and use trace output. Is there a way to perhaps automatically start the service upon installation, and have it stop at break points? Or is there another method?

View 2 Replies View Related

Android :: Running Activity From Remote Service

Apr 29, 2010

Iam trying to run an activity from diffrent package from my remote service:

This is how i implement the service.java

CODE:....

Ive also added a line in the manifest of the service:


The service works fine, but i cant run the activity -> PushActivity which is in diffrent package of diffrent application, this is the error:

Activity not found Exception: No Activity found to handle Intent {act=com.pushservice.PushServiceActivity flq=0x10

View 2 Replies View Related

Android :: Multithreading And Progress Dialog With Remote Service

Apr 28, 2010

I like to do some long running initializing work in a remote service, and during that, a progress dialog shall be shown. So basicly, I invoke ProgressDialog.show, run a oneway method of the service with a callback to be invoked when it's finished, and in the callback dismiss the dialog. I expected the service method to work in it's own process while the activity shows the progress dialog. But what happens instead (according to debugger and logs) is: ProgressDialog.show and service method invocation return immediately, then the service method is processed, and finally the progress dialog is shown for a few milliseconds right before it's dismissed. Even a "not responding" error might occur during that. If I invoke the service method in an own thread, which (as it's to be expected) is finished long before the service method is done, everything works fine. But I don't get why this is necessary. Why does a remote service method block the Activity thread? This even happens if the service method only does a Handler.post and returns immediately.

Simplyfied code overview: Activity: public void onStart() { startService(...); bindService(...);}

View 2 Replies View Related

Android :: Bind Remote Service - That Installed On Device

Sep 5, 2010

I have coded this service, that computes stuff and i want other applications to be able to bind this service, i.e. i want to enable other programmers to communicate with this service. problem is, this has to work without these other programmers to get access to the source code. just the (installed) apk with the remote service is given (and of course a detailed description of the service' interface)...problem is, eclipse keeps braggin' about that the packages of the service are not available in source code...

View 1 Replies View Related

Android :: Aidl Remote Service Call Namespace

May 16, 2009

I didn't find a sufficient answer to my problem in any posts, if there already is one, please excuse and point me to it, thanks. I made 2 projects. project 1 hast an activity that binds to a service from project 2 on a button click (all just for testing).

How can I make project 1 know (import) my TestInterface (from TestInterface.aidl out of project 2) for usage in: "TestInterface mService = (TestInterface) TestInterface.Stub.asInterface(service);"

without adding project 2 to the build path, because if I'd have an installed service without the project code, I couldn't do it this way, too...?? I read in one thread that TestInterface.aidl should just be added to project 1, too, but if I do this, in DDMS enforceInterface() complains and seems to just see/use the interface from project 1 and it doesn't work.

2. issue:...............

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved