Android :: When To Use Service Vs Singleton?

Aug 25, 2010

I'm quite new to Android development. When is it a good idea to create an Android Service instead of just using a simple Singleton class?
Take, for example, the data layer downloading information feeds from the internet. Using a Service seems too much for some cases but sometimes I might need access to a Context so I'm a little unsure about how to design the app.

Android :: When to use Service Vs Singleton?


Android :: Service Vs Singleton?

Apr 9, 2010

Android has such concept as a Service. It makes sense for interprocess communication. But if I need this service from Activities running in the same process regular singleton seems to be more convenient. No need to register, to bind. Are there any benefits to use service in the same process?

View 17 Replies View Related

Android :: Need To Create Singleton Service?

Feb 11, 2010

I'd like to know if it's possible to create a Singleton Service throughout an application ? Let's say I'd like to cerate a Service to play some mp3... I'd like it to be a Singleton, we don't want two mp3 tracks playing through each other (well maybe some would want that, but in my case I'm not making a DJ app) :P Also this Service should be somewhat dynamic as in there should be some interface so that I can stop, pauze and play the mp3 file/ stream. Now I have a couple of questions : - is this feasible ? - should I be using a Service or something else ? - how can an interface be set up in between an application and a service so that I can start, stop, pauze stuff ? - can there be something like a Singleton Service?

View 9 Replies View Related

Android :: Singleton In Different Service Which Share Same Process

Mar 25, 2009

I have two services, both of them lies in separate apk, which run in same process. The two service share same jar file by <uses-library> method. The jar file implement a class, say "test", is a singleton. But I found that two instance of test is created under this case, could anybody give me some tips? I want to ensure it's singleton. Code...

View 8 Replies View Related

Android :: Singleton Object With Context?

Oct 10, 2010

I often run into the following dilemma: I need some singleton-like object in my app (typically some central manager-like thing) and this object needs a context for various things. This means that I either have to pass a context to all methods needing one or have some sort of init-pattern to the object. Neither is pretty I think. What is the correct way of doing this? Or is this simply (even the definition of) a Service?

View 15 Replies View Related

Android :: Singleton Wrapper For Context

May 3, 2010

I'm considering creating a singleton wrapper for a Context so my model objects, if necessary, can open and read from a database connection. My model objects do not have access to a Context, and I'd like to avoid needing to pass a reference to a Context from object to object.I was planning to place into this singleton a reference to the Context returned by Application.getApplicationContext(). This singleton object would be initialized in my custom Application instance before anything else would need to or have a chance to use it.Can anyone think of a reason to not do this?

View 3 Replies View Related

Android :: How Does A Singleton Behave In Different Processes?

Mar 23, 2010

I have a singleton class and I am using it to access databases. I would like to know how it would behave if I use the same from my remote service class which runs as a separate process. Will it create a new instance in that process or will it use the instance from the other process?

View 3 Replies View Related

Android :: How To Implement Singleton With Strategies?

Aug 17, 2010

I'm adapting Image Downloader from Google Android blog. I want ImageDownloader to be singleton since I'll be using it in multiple places in my application. I want also to be able to manipulate Bitmaps using different Strategies (eg. produce transparent bitmaps).I want to be able to use ImageDownloader in one activity and set transparent bitmaps, and in another use the same ImageDownloader but get black&white bitmaps using different strategy object.

View 5 Replies View Related

Android :: Living Singleton Not Recreated

Sep 1, 2010

I have a singleton in an activity. When I end my application (like pressing back button), and start it again after some time, the singleton is not recreated, but is holding previous state. Singleton is not destroyed if the application is destroyed? Do I have to null its static members in onDestroy() to avoid memory leak.

View 1 Replies View Related

Android :: Is AudioTrack Fundamentally Designed To Be Singleton?

Dec 14, 2009

Is the AudioTrack fundamentally designed to be a singleton? Methods on the OnPlaybackPositionUpdateListener receive just one argument, which is the AudioTrack itself. And since the AudioTrack does not have getTag/setTag methods I don't see any way to distinguish among multiple AudioTracks in the OnPlaybackPositionUpdateListener methods short of keeping track of references. So, if it's so why it's not implemented as a singleton? Any thoughts. I am trying to implement concurrent use of the AudioTrack. Anybody has any experience with this approach? Am I wasting time?

View 3 Replies View Related

Android :: Live Singleton After Ending Activity

Sep 1, 2010

On Wed, Sep 1, 2010 at 1:19 PM, siva <sivaraj.r...@gmail.com> wrote: > I have a singleton in an activity. When I end my application (like > pressing back button), and start it again after some time, the > singleton is not recreated, but is holding previous state. Singleton > is not destroyed if the application is destroyed?

View 4 Replies View Related

Android :: Singleton / Intends Global Object?

Mar 17, 2009

In order to communicate with the server I need a huge global object (class with some hashmaps). all my activities (about 10) need that huge global object. which options do I have? I am thinking about passing the object using intends and about the possibility to make the object a singleton. using the db will be much too slow.

View 3 Replies View Related

Android :: Slickest Way To Use Broadcast Receiver In A Singleton?

Sep 17, 2010

I have a singleton which stores some prudent information about the user of my application. At the moment, it stores the user's login and the user's location.The location is found via a Service. At the moment, the Service references my singleton directly to stuff the longitude and latitude into it. I would like to use a Broadcast Receiver to send a broadcast that the singleton hears and uses to update the values, instead. However, to register the Broadcast Receiver, I need a Context in my singleton. What is the slickest way to achieve what I'm wanting. Is Broadcast Receiver possibly not the appropriate object? Also, what problems am I looking at with using a singleton? I assume that Android will possibly reclaim this memory at any given time (which would obviously be bad); so how can I prevent that? Would passing in the application's Context and storing it in a member variable thwart this? The Android documentation states: "But, the life cycle of a static is not well under your control; so to abide by the life-cycle model, the application class should initiate and tear down these static objects in the onCreate() and on Terminate() methods of the Application Class," but I'm not entirely sure how to accomplish this.

View 1 Replies View Related

Android :: Safe To Keep Reference To A Thread In A Singleton?

Nov 15, 2010

Let me give you the scenario.

Say that my first Activity that loads up, also creates a thread, which will run indefinitely in the background.

Now, if I move to another Activity, I assume that the thread that I initially created in the main activity will continue to run.

So, now to my main question - in order to manage this background thread from other Activities, is it safe to store a reference to that thread in a singleton object?

View 2 Replies View Related

Android :: Can We Pass Singleton Class's Object Via Intent?

Sep 3, 2010

Can I pass a singleton class's object from one activity to another activity using intent? I am using singleton class as image class img = image class.get Instance();, so i need the img instance for another activity, how can i pass an object instance in Android.

View 2 Replies View Related

Android :: Singleton Objects To Save State Or Share Data Between Activities?

Nov 24, 2010

It would be nice if StackOverflow had a section where we could post tutorials like mine so that I can answer literally hundreds of questions that have been asked here with a single blow. See... every day I read questions about how to pass complex objects between activities, how to save state so that your app can resume after orientation change, how to update listviews when the data changes, etc, etc. Here is the second part of a tutorial series I posted on my blog... I hope that you actually read it... because I haven't seen any examples like it anywhere... and it has changed how I think about developing for Android across the board. The question is... is there a downside or negative affect of developing like this?

Beyond Smart Lists - How Observable Singletons change the game. Please read through both of these tutorials carefully... I will answer any questions about it here that I can... I really want to know what you think about this and if it might solve issues for you. NOTE TO MODERATORS: there are no advertisements of any kind on my blog.. so don't just close this because you think I am spamming somehow... I am not going to duplicate my post here.

View 1 Replies View Related

Android :: Does Android Ensure That An Activity Is A Singleton?

Aug 3, 2010

If an Activity is a singleton in practice, I think I can gain some efficiency by declaring appropriate members "static", with zero risk. Yes?

View 4 Replies View Related

Android :: Showing Toasts In A Service From Worker Threads With Service Reference

Jun 24, 2009

I have a service running in the background.I have a background thread that gets a reference to the service from the application's main activity. But when the background thread calls a method in the service to display a toast, I get the "Looper not initialized exception".Why,if I have a valid, bound reference to a Service, does this still happen?

View 4 Replies View Related

Android :: Unable To Start Service Intent Service Not Found

Aug 20, 2009

I am getting following message when i try to launch service.Also is there any specific path on file system where we need to place the .apk file which contains my serivce component only.

View 2 Replies View Related

Android :: Service Auto Restarts On Breakpoint When Debugging A Service

Jul 22, 2010

I am trying to run the sample soft keyboard included in the SDK. I am using the debugger, and the literature says that to use a breakpoint while debugging a SERVICE, I need to include:

android.os.Debug.waitForDebugger();

So here is the portion of the code I modified:

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

I have put a couple of breakpoints, at the statements indicated by the comments.

This is what happens: the debugger first stops at the breakpoint1, for a few seconds. But then the service restarts. For the life of me I can't figure out what makes the service to restart.

View 3 Replies View Related

Android :: How To Get Interface On Service Without Destroying Service At Unbind?

Mar 1, 2009

My service works exactly the way i want as long as i use start and stop and communicate using intents. However my activity needs to change the state of my service as well as retrieving state information.So i thought it would be nice to broadcast some kind of state_changed event from my service and use a binder interface to pull information from the service or change the services state based on user input.This works fine too. The only problem is that my service gets killed when i unbind it just as the documentation says.Is there any way to keep the service alive but still get an interface to control it directly. My activity offers the user a way to stop the service and the service kills itself anyway after it's work is done but i don't want the service to stop every time the activity is destroyed.

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 :: Two Threads And 1 Service / Or Service Per Thread?

Nov 20, 2010

what I'm trying to do here is implement something like a peer-to-peer client. Being that, it will start a client thread and a server thread.I know Services themselves run in the main GUI thread, so I'll have to start a couple of independent threads (or Asynctasks?) for each server and client. The only thing I'm not so sure about is if I'll better have 1 Service starting 2 threads, or maybe 2 services, each one of them starting their own thread.

View 2 Replies View Related

Android :: Get System Service In Personal Service?

Nov 30, 2009

I got an problem on getting the TelephonyManager in my personal service. The code as below: public class MyService extends Service {@Override public IBinder onBind(Intent intent) { return mBinder;}

View 4 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 :: Bind To A Service From Another Service On Droid?

Sep 30, 2010

Please show me how to bind to a Service from another Service on Android.
If you have an image to show how to do.

View 1 Replies View Related

Android :: Tips On Making An Android Service / Which Polls Web Service Handle Bad Connectivity

Jul 16, 2010

I am developing an Android app which needs to poll a specific webpage in time intervals. I've got it to the point where it does indeed poll the page on a specific interval, and that interval is specified in a SharedPreference which can be changed by the user in the settings page of the app. But complications arise when network connectivity is flaky.For example, how do I ensure that the Service "wakes up" the network adapter and gives it ample time to connect before polling the page, in the case that the phone was sleeping to save power? This polling action can happen as little as once every 24 hours, so I don't want to miss one action just because the network was out (but turned on a few seconds, minutes, or even hours later).

Or there are times when the web service doesn't respond, or DNS doesn't respond, or what have you, and for any reason it doesn't get a response even though the phone is technically connected. What sort of rule do I put in place to make this retry later, so that I'm not retrying repeatedly when the user specifically turned off their internet but I'm retrying soon enough that if it was just a hiccup, the data can be received soon after the first try?Are there any examples for this type of situation? What is the logic to best handle this?

View 1 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 :: Service Stopping Another Service

Feb 17, 2010

i have a question about Services in Android.I have a application with two Services A and B.Is it possible that Service A can stop Service B?I dont want to do it through a Activity, cause the Application will be in Background. If some special Event happen in Service A, then it should tell Service B to stop. How can i do that?

View 1 Replies View Related

General :: Galaxy S2 - Service State Says Out Of Service Or Radio Off

Jan 10, 2014

I have a galaxy s2 and after I installed costom roms I dont have any signal what so ever.

I tried with like 3 roms and the same result.

I tought it was a modem problem and I tried to install some modems and see if that works. But it didnt.

My Service State says Out of service and sometimes it says Radio off.

View 1 Replies View Related







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