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
Mar 17, 2010
I'm writing a simple tile based game using a canvas and a 5X5 grid of tiles. To determine if a tile is clicked I look at the MotionEvent supplied by onTouch. I get the coordinates when MotionEvent.event is ACTION_UP and translate to tiles. This works great on the emulator but when I touch on a device the actual coordinates of the touch register higher than I'd expect as a end user.
I'm wondering what strategies people have used to get a closer to "expected" result. Do you use a simple Y offset? Do you average the coordinates over the life of the touch? Do you use other methods?
View 4 Replies
View Related
Oct 27, 2009
I have an application that uses the Google Maps API to geocode distances between lat/long pairs as a way of displaying people near to you on your phone (currently Android, working on iPhone). The issue is that even with a test group of 40 users, we are taking upwards of 10 seconds to do our calculations and send the results back to the users. While 10 seconds sounds like a long time, it's not really an issue as far as the client app goes because it's not a real-time update of people's locations (the updates occur every few minutes). Obviously this is a problem though since we'd obviously love to ramp up to tens or even hundreds of thousands of users. I'm curious if anyone else has any experience in this arena in regards to using the Google Maps API for calculating distances between points for large volumes of data?
As an aside, we're using Rails on the server, which is where all of the location calculations are occurring. The phone(s) are merely displaying the maps and updating the server with lat/long coordinates.
View 3 Replies
View Related
Jul 10, 2010
There are a number of posts (both here & elsewhere) about why a MapView might not be displaying tile info (personally, I've liked http://stackoverflow.com/questions/1809507/android-hello-mapview-tutorial-map-tiles-do-not-load, but there are other good ones, too).
My question is slightly different: I'm not getting tile info to show up (on my handset or in the emulator), and I'm looking for advice on what to try in order to debug this problem. As far as I can tell I've correctly located my debug.keystore, and used the Java JDK keytool to get the signature from it, which I then plugged into the Google web page, and then plugged THAT key back into my XML file. The app runs ok, it just doesn't display any tiles.
I was hoping that if I did something wrong here I'd see an error message in, say, logcat (or an exception that Eclipse might catch) that would confirm that this is the source of the error.
So here's my question - what would y'all recommend someone try in order to figure out what the actual problem is?
View 1 Replies
View Related
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
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.
View 1 Replies
View Related
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oct 7, 2010
How to implement tabs in Android. I am having a context. In that I want 3 tabs named Free,TOP,Paid.Clicking on each of the tab should open separate activity.
View 3 Replies
View Related
Feb 18, 2010
I'd like to implement drill down view in Android. Currently, onListItemClick, I refill the same list view with different data. any other suggestions? Something like the way it is done using UITableView on iPhone? is it possible to animate (push left or right) the listview fill operation?
View 4 Replies
View Related
May 30, 2010
I have a widget that periodically updates itself (hourly) to display top result of search query. I would like to extend it so it captures several top results and then loops through these. The best example would be Genie News and Weather widget for which I was unable to find a source code. What would be a good way to implement the animation? I'm thinking ViewAnimator + timer, but is there maybe a better way, say FrameLayout + alerts? I'm already using AlertManager to periodically pull search results for the widget How bad such arraignment would affect phone's battery life?
View 1 Replies
View Related
Jul 13, 2009
Is there any available guide to implement TLS for Android applications?
View 2 Replies
View Related
Oct 16, 2009
I am porting GPS to Android now. I have been look for many web site relate to Android GPS porting include this group. However, I also feel confused about that. I have some questions. Can anyone give me some suggestions and I will appreciate about that. 1.There are 3 files : Android.mk, gps.cpp and gps_qemu.c in hardware/ libhardware_legacy/gps. What is the functionality about the 3 files in directory gps. Should I modify the 3 files to implement GPS. In this web site http://www.netmite.com/android/mydroid/cupcake/development/pdk/docs/g..., it shows that anyone that want to integate GPS with Android should create a shared library named libgps.so refer to gps.h. My question is how to create a shared library libgps.so.If the libgps.so is created, where can I find it. What is the relation between libgps.so and libhardware_legacy.so. 3.How to test GPS if gps is implemented successfully. I know there is a gpstest tool in Android but I don't know how to use it. Can someone tell me the detail about gpstest tool provided by Android.
View 5 Replies
View Related
Mar 15, 2010
Say I want to define that an URI such as: myapp://path/to/what/i/want?d=This%20is%20a%20test must be handled by my own application, or service. Notice that the schema is "myapp" and not "http", or "ftp". That is precisely what I intend: to define my own URI schema globally for the Android OS. Is this possible? This is somewhat analogous to what some programs already do on, e.g., Windows systems, such as Skype (skype://) or any torrent downloader program (torrent://).
View 2 Replies
View Related
Feb 7, 2010
Im having problems with implementing the double tap. Well i implemented the ongestureListener and i had the gesturedetector, but im not sure wheres the problem here is my code...
View 1 Replies
View Related
Nov 22, 2010
Let's say I randomly generate a number 0 to 100. Where 0 is really cold and 100 is red hot. Wen the number hits, it would show an image bar (kind of like a % finished bar) that shows in the image what # you hit.
So it would kind of be like a progress bar from 0 to 100, and whatever # they hit it shows in the image of the bar in an imageview?
View 1 Replies
View Related
Jul 20, 2010
I've got 2 classes GLLayer and GLCamTest. I'm attempting to run a method located in GLCamTest...
CODE:..........
I'm looking to run in on a thread from GLLayer but from what I understand I need a Handler..
CODE:.........
I'm starting the Thread from within public void onDrawFrame(GL10 gl) { my question is how would I implement said handler? I've read http://developer.android.com/reference/android/os/Handler.html but I still don't really understand how I'd implement it.
View 1 Replies
View Related
Aug 3, 2010
I would like to implement a new LocationProvider. In this case, one that uses OpenCellID.org. I figured the pattern wou be quite similar to providing an AccountAuthenticator but was stunned that I could not find any documentation on this.
Looking at the source http://www.netmite.com/android/mydroid/frameworks/base/location/java/... all the relevant code seems to be in a service providing the ILocationManager.aidl -interface that I cannot navigate to or find using Goole Code Search.
Is it supported to provide your own LocationProvider at all? If so, what do I have to do to acomplish this?
View 2 Replies
View Related