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.

Android :: How to get Local Service instance


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 :: Identify Among Various Service Instance

Nov 6, 2009

Im creating a mail application, where i need to start a service instance for every account, which will check for the new mails for that account. Now my problem is that i want to identify how my service i have created so far (by calling startService()). And also i want to stop a specific instance of service. I know that calling stopService() will stop all the instances of that service. Is there any work around to it.

View 2 Replies View Related

Android :: Create Only One Instance Of Service

Sep 11, 2010

How can I make sure that only one instance of Service is created?

I have checked some functions with logging (WeatherService is the class who extends Service):

CODE:........

It gives different hash codes even when I am sure that the same function is running twice (downloading):

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

I am binding a Activity to the service with:

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

And the service can run for minutes until it is completed, therefore the service can be binded to/created by many Activities.

View 1 Replies View Related

Android :: Get An Instance From A Service Running?

Feb 16, 2010

I have a service running in background. I start it from an Activity, but i want to recovery an instance of that service from other activity (in the same app) in order to call one method.

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 : 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 :: 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...............

View 1 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 :: 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

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

Android :: How Local Service Can Invoke A Sync Method On It's Main Activity?

May 2, 2010

I've configured local service under some app i wanna know how could i invoke methods on the activity, through the service in a synchronous way for example the service invoke a method inthe activity and waiting for for result(synchronous) from it.

View 2 Replies View Related

Android :: Publish An Application Update On Android - Market Without Deleting Local Database And Local Files

Nov 11, 2010

I published an application that stores data in a local database.

Now I have to publish an update to this application to fix some little bugs, but I am afraid that downloading and installing the update will delate the local database associated with the previous version.

I would like to know how the update system works. Will installing an update completely delete all the apk, files, databases associeted with the previous version?

If so, how can I avoid this in my code?

View 2 Replies View Related

Android :: 2 Instance Of Same Activityes

Apr 2, 2009

My application has 2 activities. The main activity will create the "child" activity through startActivityForResult((...). When the child activity needs to exit, it calls setResult(..) and finish(). Child activity will start and exit multiple time upon user selection. The activity are start and exit as expected and onAcitivtyResult(..) also got invoked.

However, I found a problem with child activity, when the child activity was created the second time ( Main activity called startActivityForResult(...) upon some user event ), a new instance of child activity was created, but the displayed is the FIRST instance child activity! ( so any state in second instance of child activity was not accessible ). The onKey(...) was always go to first instance of child activity. Make things more interesting, the getInstanceCount () returns 3.

I have checked the code and no where holds the first instance of child activity which should be garbage collected after finish().

View 3 Replies View Related

Android :: More Than One Instance Of Application

Apr 9, 2009

Is there a way to prevent the user of opening more than one instance of my application?

For example: User clicks on App and opens it. The user clicks on the home button. (the app is still running in the background) The user clicks on (not the menu button, but the button above it in the homescreen), and then opens the application again. Does it open the same instance, or does it create another one? If it does create another one, how can I prevent it from creating another one, and just opening the existing instance?

View 6 Replies View Related

Android :: Get Instance Of The Activity?

Jul 9, 2010

Is there a way to get an instance of the activity that has called the currently running activity from the intent object that has been passed to it? eg. if A has called B, I would like to retrieve A's instance from the intent in B's onCreate method. As Activity is not Serializable i am not able to pass the instance in the extras bundle.

View 1 Replies View Related

Android :: Launching New Instance?

Sep 7, 2010

I have two activities.A and B. A starts B.Both are running in the screen and both are visible. Say now B is visible.

On a special key press, I want to bring the A to the front and make it active. The problem I am facing is when the special key is pressed, another instance of A is launched and the new instance is brought to the front.

But I want the original A to come to the front. I want to make this change in the framework layer rather than application specific by using the singleInstance theme in the launchMode in AndroidManifest file.

View 5 Replies View Related

Android :: Instance Of Widget Currently On Homescreen?

Jun 24, 2010

Is there a way to know if there is an instance of your widget currently on the homescreen? I always end up using variables that change state with onUpdate() and onDeleted() calls, but that obviously that isn't effective in every scenario.

View 9 Replies View Related

Android :: Display Calendar Instance

Nov 22, 2010

I have referred the example given on: http://goo.gl/1uxXv , But it is not showing the exact DatePicker dialog as given in the book example, what i should do to display the same dialog box or Calendar instance in my application ?

View 4 Replies View Related

Android :: Get File Path From URI Instance

Nov 17, 2009

I am trying to do the following.

I have an Image viewer where in the user picks an Image from within the gallery. The uri to that selected Image is available to me. Now, I want to use this URI information and send it as a file over a socket using FileInputStream. Is this a valid syntax to perform the above action?

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

View 10 Replies View Related







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