Android :: Communicate Progress From Local Service

May 16, 2010

An application I'm building uses a local Service for downloading files from the web to the phone's SD card. In this app users can browse lists of books, and read them while online. A user can also download a pdf copy of a book for offline viewing. To handle downloads I'm using a locally bound Service. I do not want this Service to run all the time, only when downloading files. So that the Service can shut itself down when its tasks are complete, I am not binding to the service, rather I'm sending an "enqueue for download" command through the Intent passed to Context.startService.

Books available for download are shown in a list. A user can choose to download a book by clicking on its row in the list. On download, I need to show download progress using a ProgressBar on the actual book list row. I need to also show, on the rows, if a book is enqueued for download, or if its download has completed or failed. The books can be shown in different activities throughout the application--in search, or in the user's list of favorite books, for example. When the books are shown in different places, these are not the same objects, but they are uniquely identified by their bookId...............

Android :: Communicate progress from local Service


Android :: How Does A Service Communicate With Activity?

Feb 17, 2010

Suppose I have an Activity that's a list. It calls a Service when this Activity starts.The Service will do background stuff download, parse, and fill the list.My question is this: How can the Service communicate with the Activity?How can I call a method in the Activity, from the Service? (I'm new to OOP)

View 2 Replies View Related

Android :: Communicate With A Service From An Application

Aug 25, 2009

i have some problem to communicate with a service from an Android application.The service is in a first package "package com.myService" and the application in another on "package com.myApplication".My service work and start well but my next step is to add an AIDL interface to external applications.I have tried to follow the recomandation described here : http://developer.android.com/guide/developing/tools/aidl.html, but i have still the following error (given in the log service):W/ActivityManager( 568): Unable to start service Intent { action=com.MyApplication.IBootstrapService }: not found

View 2 Replies View Related

Android :: Service - Communicate With Activities

May 19, 2010

I'm wondering which is the best way to communicate between a Service and an activity..

Broadcast intent
Callback
others?...

View 1 Replies View Related

Android :: Getting Service To Communicate With Activity?

Jun 25, 2010

I currently have a Service and an Activity in my application.I currently bind the Service to the activity without using AIDL as the Service and the Activity are in the same application.This allows me to call the methods from the Service within my Activity when I require them, however it doesn't let me call the methods of the Activity from within my Service when I want to.Can anyone comment on what would be the best way to achieve this?I could use Intents but is there an alternative option?I want to have tight communication between the Service and the Activity, I want to be able to call an Activity method from my Service when an event happens.

I now have it working the way I want, however I have come across a problem.My service gets status updates and my Activity is then supposed to react to the update sent on from the Service.The problem is that when I start my activity I get the Dialling Status and then Connected status before the onBind is called and I get the instance of iCallDialogActivity.

I need to be able to use my iCallDialogActivity when I get the Dialling and Connected Status notifications.But this gives me a NullPointer Exception due to it not being created in time when my Activity starts, binding is the first thing I do in my Activities onCreate().Is there a way to make it bind straight away?

View 1 Replies View Related

Android :: Want Activity / Service To Communicate With Intent

Aug 2, 2010

In the Activity I write Intent i=new Intent("IntentServiceTest"); Bundle bundle = new Bundle(); bundle.putString("abc", "def"); i.putExtra("wer", bundle); IntentTest.this.startService(i); Start Service into Service OnCreate method,but I don't know how to do get this Intent in this method.

View 11 Replies View Related

Android :: Best Way For Service That Starts Activity To Communicate With It

Feb 16, 2010

I have a service that listens to a socket. When receiving certain input it is to create an activity. When receiving other input, it is to kill this activity. I have struggled for a while to make the service communicate with the activity through AIDL (http://developer.android.com/guide/developing/tools/aidl.html), but this seems to not be effective. I think AIDL is only effective when the process that is to be talked to is a service, not when it is an activity? I would love some directions or suggestions on how to solve my problem.

View 1 Replies View Related

Android :: Communicate Between Applications (service Vs Intents)

Sep 13, 2010

What is the difference between 2 ways of interaction between applications on android:

1. implementing service in app #1 and using it in app #2.
2. handling intentions and posting answer intention.

View 2 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 :: How To Communicate Back To Service From Broadcast Receiver?

Aug 17, 2010

I have a widget which starts a service. The service registers two broadcast receivers. I would like to send back intents from the receivers to the service, so that the service can react.I remember reading (on some blog) that this won't start a new service, but will simply pass the intent to the already running service. Is this correct? Is it a bad way of doing it? Is there a better way?

View 1 Replies View Related

Android :: Using A Local Service ?

Jul 16, 2010

I don't see the point of using a local service in Android. If I want to do backgound stuff, I can create a thread and use Handlers.

Creating a local service is a big headache, you have to mess with Binders, worry about the start/stop/bind/unbind lifecycle, etc.

What does a local service get me that a thread doesn't ?

View 2 Replies View Related

Android :: Should I Use Service Or Local Thread ?

Oct 6, 2010

I have an application which requires networking service. I took on LWUIT4IO and adjusted it to my needs so now i have a network queue that can run one or more network threads.Now, my application is based on single root activity that spawns other child activities as needed (it's a reservation center for vacations, car rental etc.. each in it's own activity). The network is common to all and should be used by all activities. the network thread requires, basically, a callback to notify it's finished and return the result (input stream or byte array) .At first i thought that i should use a service instead of a singleton that will be started in the root activity(the service will also be started in the root activity), however working with a local service is problematic for me: 1. no callbacks which makes me use intents to encapsulate the request esponse in intents time consuming, also since there is not single point of listening (i have to use BroadcastReceivers)i have to add a calling class name or some other identifier so the sender of the request will know it's for him, i think this is also a waste of time and resources since i need only one listener.

i think i CAN use callbacks if i use Binder object to return local instance of my Service and then use the queuing method directly, this is problematic for me as acquiring Binder object is asynchronous and i need it 'on the spot' 3. I thought of using a static instance of the service and null it in onDestroy of the service, but if i use that way, i'm not so sure i need a service... 4. i saw a small answer in stackoverflow about inheriting application and putting whatever member you need there so when you use getApplication you get this instance and then you can retrieve whatever you want, is this even advisable ?

View 5 Replies View Related

Android :: Should I Use Local Service Binding?

Oct 5, 2009

I am very new beginner, and I am designing a small application as below.

- After a user starts the application, he/she can click the start button to start a background task. (e.g. retrieving the news headlines periodically, then do something...)

- Even after the user quits the application, the background task still running.

- To stop the background task, the user needs to run the application again, and clicks the stop button to stop the background task.

In the above scenario, what API should I use ? (Local Service Binding ? Remote Service Binding ? Handler ?)

View 2 Replies View Related

Android :: How To Get Local Service Instance

Jun 11, 2010

I'm starting a service in my application using startService.

I do not want to use bindService as I want to handle the service life time myself.

How can I get an instance to the service started if I do not use bindService? I want to be able to get a handler I've created in the service class to post messages from the activity.

View 1 Replies View Related

Android : Local Service : How To Tell Activity When Done

Feb 22, 2009

Starting from the example ServiceStartArguments.java of the "API demos", the service "ServiceStartArguments" is creating a new Handler object (ServiceHandler) which does all the work in a separate thread. Once that work is completed, how can I tell other components that my work is finished, and also provide data (that resulted from the work) to them?

I tried something like startActivity(intent_transferred_via_msg) which does not work, I'll get an exception because I call it "outside of the service", which is technically true.

View 3 Replies View Related

Android : Can't Bind To A Local Service / Way To Fix

Sep 9, 2009

I have the following base activity. code...

View 3 Replies View Related

Android :: Use Local Service To Refresh Map UI

May 31, 2010

I don't need a strict code related answer I just need somebody to tell me what I am missing.My application has to retrieve from a web service (xmlrpc) the positions of some users I know and update their position on a MapView.So I decided to use a Service and an Activity extending MapActivity to show results.
I thought about two solutions:

I ) start the service and make it ask every minute for these positions and send them to the activity as a bundle via intent. (This didn't work out well, since once shown I couldn't find a method to let the activity continue refresh itself until she stop receiving intents+data from the service)

II ) Incorporate a thread within the activity which starts the service via context.startService(...) every minute. And the MapUI refresh itself once the service send back an intent and stop itself. (Maybe I will fall in the same problem category as before I haven't tryied yet).

I am also giving directions (via maps.google ws) in this way I'd like to refresh only users positions on the map and save the route.What Am I missing do you have any suggestions? related to activities/services internal mechanics, don't know launch modes, use broadcast receivers or intent filters?

View 1 Replies View Related

Android :: Service - Show Progress In Activity

Jan 2, 2010

I have a service that downloads something from the Internet, it shows progress in notifications and in MyActivity (only when MyActivity is on foreground of course). How should the service post the progress to MyActivity? I know this could be done somehow with IBind but can I just simply do this in MyActivity:

MySevice.myActivity = this; startService(new Intent(....));

From MyService I can now call MyActivity's methods because I have a static reference to it in MySevice.myActivity, so I can call e.g. myActivity.sendProgress(63).

View 5 Replies View Related

Android :: Does My Local Service Spawn Another Thread?

Jun 24, 2010

HTo be able to write "nice" code between my application/activies and a local service I need to understand some basic Android concepts:What I'm wondering is if my application (as in my activities) and my local service is sharing one thread. I.e. when the activities and the local service executes tasks queued are these tasks interleaved in ONE thread thus sharing the thread or does the service has a thread of its own?Also if the local service shares the thread with the activities and the local service makes a direct call (via a callback) to one of the activities (i.e. no post message) is the activity thread "halted" or is the execution of that specific function queued to be executed later anyway?

View 1 Replies View Related

Android :: Running Activity From Local Service

Sep 13, 2010

I'm trying to create a program with a service that runs every 10 seconds, puts the camera preview, taking a picture and then leaving the user to continue his work (closing down). Currently I have two problems:

1. After I'm taking the picture, the preview still there. There's no function like close() to return to the previous activity. How can I return to the previous activity?

2. I'm trying to run the above described activity from the run() function (from the timer class that execute the run() function every 10 seconds). When I do that, a runtime exception is raised. But when I start the above described activity from a button clicked (not from the timer) it works fine.

View 4 Replies View Related

Android :: Check The State Of A Local Service

Sep 30, 2010

How do I check whether the local service inside my application is running?

View 1 Replies View Related

Android :: Binding To A Local Service From A BroadcastReceiver

Sep 15, 2010

My application has the following components: 2 Activities A Service and a BroadcastReceiver

Whenever the user updates the system time, my broadcast receiver receives the Intent.ACTION_TIME_CHANGED. Now when this happens I want to reschedule a Handler in my Service. How do I bind to a Service within my BroadcastReceiver?

View 1 Replies View Related

Android :: Activity With ProgressBar - Service - Update The Progress?

Dec 28, 2009

this is the current state/situation: I have an Activity which binds a Service which creates AsyncTasks which downloads various web resources. That works well, but of course the ProgressBar shows nothing. Previously i had an Activity which created an AsyncTask which downloaded some stuff. The AsyncTask got the View which holds the ProgressBar. So i could update the progress using onProgressUpdate and publishProgress. Obviously this doesn't work any longer because I have no reference to the ProgressBar.

View 1 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 :: Sync Between Local Service With Thread And Activity

Jun 1, 2010

I'm trying to think of a way on how to sync in between a local service and the main activity.

The local service has,

A thread with a socket connection that could receive data at any time.
A list/array with data.
At any time the socket could receive data and add it to the list.

The activity needs to display this data. So when the activity starts up it needs to attach or start the local service and fetch the list. It also needs to be notified if the list is updated.

I think I would need to sync my list somehow so the local service does not add a new entry to it while the activity fetches the list when connecting to the service.

View 2 Replies View Related

Android :: One Local Service Multiple Binding Activities

Nov 20, 2010

I have a local Service to which multiple activites needs to bind. In the first launched Activity, bindService returns true and onServiceConnected is called. But in any additionally launched activites bindService returns false, and I can't get a reference to my Service.

How can multiple activities simultaneously be connected to a local Service?

View 3 Replies View Related

Android :: Local Service Not Registering - Force Closes

May 6, 2010

Essentially my problem is this, I open my Activity. It binds to a local service that "appears" to be connected. I get a force close when I press the back button:

"IllegalArgumentException: Service not registered" when unbind is called in my onPause method...
public void onPause() { super.onPause(); if (isFinishing()) {
if (mConnection != null){ Log.i(TAG,"onPause, mConnection" + mConnection.toString());
mDbS.unbindService(mConnection); }else { Log.i(TAG,"mConnection is null");
} The service is bound in onCreate // bind to our sdCard database using our Service Connection
mServiceIntent = new Intent(this,DatabaseService.class);
if(bindService(mServiceIntent, mConnection, Context.BIND_AUTO_CREATE)){
Log.e(TAG, "service bound"); }else{ Log.e(TAG, "service not bound");
} bindService is returning true.

My Service connection is as follows. onServiceConnected is called and goes to completion. onService Disconnected is never called (presumably because my service is in same process)
private ServiceConnection mConnection = new ServiceConnection() {
public final String TAG = "LoadView.ServiceConnection"; //$NON- NLS-1$
public void onServiceConnected(ComponentName className, IBinder service) {
mDbS = ((LocalBinder<DatabaseService>) service).getService(); .....
stuff not relevant.... Log.i(TAG, "finished onServiceConnected");
//$NON-NLS-1$ } public void onServiceDisconnected(ComponentName className) {
Log.e(TAG, "onServiceDisconnectedCalled"); //$NON-NLS-1$ } };

The only thing I do a little different is that I don't use an inner class in my service for the Binder object - I use a separate class. This is mostly because I have several databases and wanted code I could reuse and set up simply rather than worry about all the ins and outs and memory leak issues.

import android.os.Binder; import android.util.Log;
public class LocalBinder<S> extends Binder { private String TAG = "LocalBinder";
private S mService; @SuppressWarnings("unused") private LocalBinder() {
} public LocalBinder(S service){ mService = service;
} public S getService() { return mService;
} public void finalize(){ mService = null;
try { //TODO reinstate this after Issue 8046 is resolved
//super.finalize(); } catch (Throwable e) { Log.e(TAG,"Unable to finalize Binder");
} } }

View 2 Replies View Related

Android :: How To Have Android Service Communicate With Activity?

Mar 17, 2010

I'm writing my first Android application and trying to get my head around communication between services and activities. I have a Service that will run in the background and do some gps and time based logging. I will have an Activity that will be used to start and stop the Service.So first, I need to be able to figure out if the Service is running when the Activity is started. There are some other questions here about that, so I think I can figure that out (but feel free to offer advice).My real problem: if the Activity is running and the Service is started, I need a way for the Service to send messages to the Activity. Simple Strings and integers at this point - status messages mostly. The messages will not happen regularly, so I don't think polling the service is a good way to go if there is another way. I only want this communication when the Activity has been started by the user - I don't want to start the Activity from the Service. In other words, if you start the Activity and the Service is running, you will see some status messages in the Activity UI when something interesting happens. If you don't start the Activity, you will not see these messages (they're not that interesting).

It seems like I should be able to determine if the Service is running, and if so, add the Activity as a listener. Then remove the Activity as a listener when the Activity pauses or stops. Is that actually possible? The only way I can figure out to do it is to have the Activity implement Parcelable and build an AIDL file so I can pass it through the Service's remote interface. That seems like overkill though, and I have no idea how the Activity should implement writeToParcel() / readFromParcel().Is there an easier or better way? Thanks for any help.

View 2 Replies View Related

How To Connect To Local PC Web Service

Jul 2, 2013

I have an android app that must connect to my local webservice with soap but I cant seem to get it working. This is the code I have.

[HIGH]public void Hello()
{
String SOAP_ACTION = "http://tempuri.org/Hello";
String METHOD_NAME = "Hello";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://10.0.2.2/MainService/MainService.asmx";

[Code]...

All this does is catch an exception with the message "Null". Note that I am not an android developer, this is my very first project.

I did the same thing with Netbeans and regular Java and it works perfectly.

View 2 Replies View Related







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