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?

Android :: Safe to keep reference to a thread in a singleton?


Android :: Volatile Reference A Safe Way To Pass MotionEvents Between Threads?

Jun 29, 2010

I am curious about the safety of this method I have considered using for passing touch events in my Android application (and testing my understanding of concurrency in Java). Here's the basics:

I have a SurfaceView hooked up to SurfaceHolder.Callback to get user input events, mainly the onTouchEvent callback. After the onTouchEvent method is invoked, I see if event.getAction() == MotionEvent.ACTION_UP and, if so, call a method I have named postTouchEvent which is a member method of my app thread that updates the application's state and draws to the canvas. Code...

Now I understand that it is certainly not atomic, but since I treat it as immutable after receiving it from framework, won't this work? (Instead of synchronizing the post method and the if statement, which I have no problem doing, but I'm asking to learn.)

Here are my thoughts. I know I will have a valid reference to the object but I am unsure in what state I will actually see the object. While testing everything is working out just fine but I am aware of how uncommon threading exceptions can be, even if something is broken.

Also, I can see one problem with this: If another MotionEvent comes though, it's possible that inputEvent in the run() method will be set to a different event than the one that was referenced when this.mInputEvent != null was checked, but this really isn't an issue.

So, is there anything I am missing or, for my purposes, should this be ok?

View 2 Replies View Related

Android :: Is SQLiteDatabase Thread-safe?

Dec 17, 2009

Is the SQLiteDatabase thread-safe?

View 2 Replies View Related

Android :: Why Is The UI Toolkit Not Thread-safe?

Nov 13, 2010

As I read at many places this phrase "the Android UI toolkit is not thread-safe"

Why is that,just I want to understand .....

View 3 Replies View Related

Android :: BitmapFactory.decodeStream Thread Safe?

May 7, 2010

Is the BitmapFactory.decodeStream method thread safe?

View 2 Replies View Related

Android : Is It Safe To Launch / Activity From A Non-ui Thread?

Jul 21, 2010

Suppose my activity ui-thread spawns a separate thread at some point. Is it safe for that new thread to fire off an Intent for launching a new activity?

View 1 Replies View Related

Android :: Is SQLiteStatement - Prepared Statement - Thread-safe?

Sep 20, 2010

I'm wondering whether prepared statements in Android (instances of SQLiteStatement) are thread-safe. In particular I'm asking with regard to the following scenario:

In a ContentProvider you create a pre-compiled insert statement during onCreate. Then, in the overriden insert method you make use of this statement by binding a set of parameters to it and calling executeInsert on it.

We know that a ContentProvider has to be written in a thread-safe manner. If SQLiteStatement does not bind parameters per thread, a concurrent call to the provider's insert method would alter the statement's bindings and result in unpredictable behavior.

Android's own Contacts provider uses prepared statements in this way (http://bit.ly/bDuKAT), so I tend to believe that they are in fact thread-safe. Looking at the source code of SQLiteStatement I don't see how though (http://bit.ly/9M1Swv).

So, is SQLiteStatement (or SQLiteProgram that is) thread-safe with respect to parameter binding or not?

View 1 Replies View Related

HTC Incredible :: Thread Dedicated To The Safe Removal Of Apps

Jun 30, 2010

I want to see a thread for my own sake and others on what apps people have removed and what is safe.In order to remove an app use these directions.Footprints: (I had to do a Nandroid backup after removing this becauuse maps would not load in navigation) some online have reported the same problem while others here said it worked for them) JUST BE SURE TO MAKE A BACKUP FIRST.Another app to watch for is Friendstream as people have reported problems with constant sync issues.(Also just a question when removing apps do you need to run the same command line ending with .odex?)

View 38 Replies View Related

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

View 1 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 :: 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 :: 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 :: 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 :: 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 : Java - Implement A Run Method Of Thread If Create A Thread Global

Sep 7, 2010

How can I implement a run() method of thread if I create a Thread Global?

I mean If I create a Thread Globally then can I implement its run() method {" public void run()"} anywhere in my Application?

In the run() method I have to write the code to perform some action.

IF I can do it then please can anyone show me briefly how to do it particularly.

View 2 Replies View Related

Android : Handle Messages Between The Main Thread(the Deafult UI Related Thread) And The User Created Gamethread

May 21, 2009

I am writing an application in which i need to handle messages between the main thread(the deafult UI related thread) and the user created Gamethread.

The requirement is like this.

An activity(say "Activity_X") is setting the view by "setContentView(some "View_Y")". In "Activity_X" i have implemeted "onCreateOptionsMenu()" and "onOptionsItemSelected()" fucntions for creating menus & a switch case for action to be taken on selecting those menus.Menu has items like "resume/pause/zoom/" .

All action to be take on selecting these menus are implemented in "View_Y" in a separate Gamethread by extending "Thread" class.

So whenever a menu is selected in "Activity_X" i need to send a message to "View_Y". And on receiving this ,a particular action/method should be called in View_Y(GameThread).

How can i achieve this using Handlers?Is there any other way of doing this? Please do share with me some code snippets for these.

View 3 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 :: Update ListView In Main Thread From Another Thread

May 27, 2010

I have a separate thread running to get data from the internet. After that, I would like to update the ListView in the main thread by calling adapter.notifyDataSetChanged(). But it does not work. Any workaround for that?

View 1 Replies View Related

Android :: Use Thread With SurfaceView - Ie Draw In Separate Thread?

Jul 22, 2009

I want to do the drawing in another thread to speed up the game(it is way to slow right now). I was told to do this but don't quite understand why that would speed things up. Is it GameView that should implement Runnable? Should I make the thread sleep when not drawing? where should I start the thread? package com.android.WWS;

import android.app.Activity; import android.content.Context; import android.graphics.*; import android.os.Bundle; import android.view.SurfaceView; import android.view.KeyEvent; import android.view.View; import android.view.View.OnKeyListener; import java.lang.Runnable; import java.lang.Thread;...................

View 4 Replies View Related

Android :: Suspend / Resume Thread From Another Thread In Same App

Feb 20, 2009

I need to suspend/resume a thread from another thread in the same process. I tried to look into thread apis,but I couldn't figured out a way to achieve this.Can anyone pls point me some references to look or give a tip to do this.

View 2 Replies View Related

HTC Droid Eris :: Remove Certain Texts From Thread In Easily Instead Of Whole Thread?

Dec 28, 2009

Does anyone know how to delete certain texts from a thread in an easy manner instead of having to delete a whole thread??

View 7 Replies View Related

Android :: Main Thread The Same As UI Thread?

Jul 16, 2010

The Android doc says "Like activities and the other components, services run in the main thread of the application process." Is the main thread here the same thing as UI thread?

View 3 Replies View Related







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