Android :: Two Android Threads And Not Synchronized Data
Apr 6, 2010
im using 2 threads, one is writing floats and one is reading this floats permanently. my question is, what could happen worse when i dont synchronize them? it would be no problem if some of the values would not be correct because they switch just a little every write operation. im running the application this way at the moment and dont have any problems so i want to know what could happen worse?
a read/write conflict would cause a number like 12345 which is written to 54321 and red at the same time appear for example as 54345 ? or could happen something worse?
(i dont want to use synchronization to keep the code as fast as possible)
View 3 Replies
Apr 13, 2010
What are the advantages/disadvantages in placing a lengthy network access code in a thread in an activity or a thread in a service? How would it affect the application? I am writing a streaming audio player and from what I've read so far putting the code in a service will still end up blocking the application so a new thread is needed, does anyone know if it makes more sense to put this piece of code in a service.
View 1 Replies
View Related
Aug 24, 2010
What does this line from the following code sample mean? "synchronized (_surfaceHolder) {_panel.onDraw(c);}"
I can guess what it does, but what is it called and how does it works? Is it a nameless synchronized function? Code...
View 2 Replies
View Related
Dec 17, 2009
I'm coming from .NET world, and unfortunately looking Java source with .NET's eyes. Following code is from Android Apps (though not Android specific at all):
private class Worker implements Runnable {
private final Object mLock = new Object();
private Looper mLooper;
Worker(String name) {
Thread t = new Thread(null, this, name);
t.start();
synchronized (mLock) {
while (mLooper == null) {....................
View 4 Replies
View Related
Jan 9, 2010
I am facing a problem with a stopping thread which is in a synchronized block. I am using TCP socket. The problem is that I am waiting on a DataInputStream object and I want to create a new socket again but it doesn't allow me to do because of the synchronized block.
I have tried with Thread.interrupted(). I cannot avoid the synchronized block. Is there any other way to do the same?
dis = new DataInputStream(ReadWriteData.kkSocket.getInputStream());
int i = -1;
String aval = ""; //new String();
char c = (char)dis.read();
It is getting blocked on dis.read().
What I should do for escaping the dis.read when I want to create a new socket?
View 3 Replies
View Related
Mar 26, 2012
how to develop an offline sync app using the OpenMobster Sync Plugin for the PhoneGap framework. You can develop your App using HTML5 and Javascript instead of the native programming language.
Features:
-two way synchronization between the local sqlite database and the corporate backend in the Cloud
-Offline mode operation. All data changes are tracked and auto synchronized with the Cloud once the connection returns
-Use of Push notifications to push data changes from the Cloud to the device
-Support for replicating changes to multiple devices like iCloud does
-A Java based Channel Framework for integrating your backend with the Cloud
View 1 Replies
View Related
Oct 18, 2010
I use a boolean variable "flag" both in main and child thread. This "flag" is used to notify child thread to exit. I only use simple operation, e.g., "flag=false", "if (flag) {}". As I know, in java, "get and set a boolean variable" is atomic. So "synchronized" is not needed for variable "flag", declaring "flag" as "volatile" is enough.
Is this still true in Android?
View 10 Replies
View Related
Mar 14, 2010
I'm looking into writing simple graphics code in Android and I've noticed some synchronized() blocks. What is the reasoning behind this and how do I know when I should be "synchronizing" my code?
View 1 Replies
View Related
May 16, 2010
Pretty pissed off by the youtube app in X10.
Sound is always late by about 0.3s.
Its a real turn off to see the mouth move first, then hear the sound.
Is there any other apps which I can watch youtube in high quality, without facing this sound problem?
Or is there another better apps out there?
View 2 Replies
View Related
Oct 22, 2010
We are in the process of refitting some of our recievers and services with IntentServices (mostly to address rare ANR issues - and because IntentService is pretty cool...). In one case we are converting a traditional service to an IntentService. The original service fired off a few methods whose job was to download data from our servers. Each of these requests would spawn a thread of their own to do the work (apparently not fast enough to avoid the occasional ANR). So now we have a question concerning the life cycle of these processes.
For example, the following situation demonstrates what is happening:
- Start Intent Service - Trigger Download1 - Download 1 thread starts - End Intent Service
- Download 1 thread continues..... - Download 1 thread ends
Our question concerns our exposure to the OS shutting down the Download 1 thread because the Intent Service has terminated before it finishes up. Not sure if it is becomes more or less likely that the OS will view it as something that can be flushed.
If the Download 1 thread is more likely to be flushed by OS we will need to take a different approach.
View 4 Replies
View Related
Apr 6, 2010
I am working on a simple application (studying purposes) which list all the files from a selected folder. On top of that I would like to have a search feature where the user can search for files (the code for that is already in place). Now, I was thinking about having the search running in the background somehow, whilst the user can still navigate, create folders, copy, sort and do other stuffs normally. When the search finishes the user would get a notification and then could click on it and go to that activity (It ideally should be the same ListView I already use for browsing the files, I would just need to update the Adapter there with the latest processed data after clicking in the notification). What's the best answer for that? Threading or AsyncTask?
View 4 Replies
View Related
Feb 22, 2010
I'm trying to understand the idea behind the Services. If it runs in the program's thread, why not create just a separate thread (or AsyncTask) to do the job? Can a service keep running in the background? For example, i want to create a task that will continuously be polling data from a server, even if the main application is not running. Can this be achieved with a Service?
View 8 Replies
View Related
Mar 13, 2010
while debugging and app that uses AsyncTask to record audio and update UI I noticed that everytime that an AsyncTask object ends running (finishes doInBackground and onPostExecute or on Cancelled it´s thread stays alive (running status).At least for me that should not be the behavior of the class since the doInBackground task may not stay running forever (as an example the android manual says that a status bar should be updated by an asynctask, and it won´t last for the whole app running time).Is there anything I´m missing, as a method to destroy it, or should I just ignore and keep creating threads as I need and the VM will handle them as it needs resources?
View 9 Replies
View Related
Jun 5, 2010
how do i save certain threads?
View 1 Replies
View Related
Aug 3, 2010
As my app matures, I find myself finding more and more uses for threads. By now I must have about 25 threads, all doing important things and working together in symphony.
I notice however that my app is sitting around 15.5MB resident. Compared to the browser (+/-35MB) I feel pretty safe, but I do notice the resident size of my app ever increasing.
The question is, how much overhead is involved with adding a thread?
I'm also wondering if the synchronized keyword encounters more and more latency with each new thread that is present?
View 4 Replies
View Related
Mar 4, 2010
I have an activity that uses a Timer (java.util.Timer) to control the display. I set it off to repeat its run() method every second or so. When it runs, it updates some View elements.
As Timer runs in its own thread, I assumed this would be reliable. But I notice that sometimes there is a stutter, or delay, in the views updating. It's like they occasionally get stacked up, and all happen together. Studying the output from logcat, I notice that this happens when the device is doing something else - some system functions, or sometimes a garbage collection.
How can I avoid this? I'm not aware I can run the main activity in a thread of its own, can I? If the timer has its own thread, why is it affected?
View 8 Replies
View Related
Nov 17, 2009
We are developing an application that needs to suspend and resume threads like a debugger (meaning in a non-safe way like Object.wait() and Object.notify()).In the Java SDK the methods Thread.suspend() and Thread.resume() are deprecated but we can still use them. Also there is the Java debugger API which allows one to do that if you connect to the VM as a debugger. Is there some API for android we can use? Is there a published Java Debugger API we can apply for Android?
View 2 Replies
View Related
Oct 30, 2009
I have a question about the background thread handling change that went into SDK 1.6. I read here that BG threads get placed in a scheduling class that can't use more than 5-10% of the CPU in order to keep the foreground responsive. Do system services get into that scheduling class?
My app uses repeating alarms. It was great with 1.5, very reliable. Since the upgrade to 1.6, the phone seems to be dropping some of my repeating broadcasts, especially if I am doing something fun in the foreground like with WIFI when the Alarm is supposed to fire. I do not have any of the task killer programs that have been a hot topic lately. To be clear, the dropped alarm broadcast behavior is intermittent. I am not 100% sure if I really am doing something when it has failed. If the timer is a one shot, it seems to work better but there is no real empirical evidence here. My phone is usually in my pocket when I fire one of the one shot alarms. If my theory about system services in the background scheduling class is correct, then I probably cannot find a workaround or defensively code a solution. Will it be the same in 2.0?
Have others seen issues with alarms and with the setRepeating method? I am looking for suggestions to troubleshoot this problem. How can I determine if the problem is the broadcast, if it is the repeating alarm creation, or if there is some other issue like low memory coming in to play.
View 13 Replies
View Related
Mar 4, 2010
I have a couple of worker threads in my app which I stop and restart during onPause() and onResume(). I use a method that clears all the reference to and from the threads when stopping. However ThreadGroup is still retaining a reference to my threads and causing a small memory leak. After pausing and resuming my app about 40 to 50 times I will then get OutOfMemory Errors when loading bitmaps. Allthough this doesn't effect most of my users I do get occasional reports of crashes. How can I remove the references to my threads from ThreadGroup so that GC can do it's job.
View 4 Replies
View Related
Jan 9, 2010
Currently I have two threads, other than the UI thread, which need to communicate with each other. Thread one needs to be able to send messages directly to thread two, and vice versa. What is the best way to implement this?
At the minute, my code looks like this...
View 4 Replies
View Related
Sep 24, 2010
When i try to delete a threads, handcent crashes. the reason i want to delete threads is because i believe my conversations of upwards 2000 messages are slowing down the handcent performance and therefore my phone >
anyone else have this problem or know a way to delete all that garbage?
View 2 Replies
View Related
May 17, 2010
I'm writing a live wallpaper, and I'm forking off two separate threads in my main wallpaper service. One updates, and the other draws. I was under the impression that once you call thread.start(), it took care of everything for you, but after some trial and error, it seems that if I want my update and draw threads to keep running, I have to manually keep calling their run() methods? In other words, instead of calling start() on both threads and forgetting, I have to manually set up a delayed handler event that calls thread.run() on both the update and draw threads every 16 milliseconds. Is this the correct way of having a long running thread?
Also, to kill threads, I'm just setting them to be daemons, then nulling them out. Is this method ok? Most examples I see use some sort of join() / interrupt() in a while loop. I don't understand that one...
View 1 Replies
View Related
Jun 24, 2010
I have two questions about sensor listeners
1. from which thread are sensor values updated and should this be synchronized? can sensor's listener callback be a good place to call custom's view onDraw method? as this should be done from different thread. I cant find anything about it. In another words my problem is that I want to listen to sensors change and draw something on view surface but I dont know which thread (the main thread of the application?) is updating sensor's state
2. If I register sensor listener with SENSOR_DELAY_FASTEST my application is not responsive at all! Raw application with TextView only is not reacting to go back or home button! How should I deal with this or am I doing something wrong?
View 4 Replies
View Related
Sep 13, 2010
Trying to understand the Android framework model. I have an application that needs to have several threads running. On thread gets GPS fixes, another picks up GPS fixes and pushes them to server, and yet another occasionally polls a server for dispatched orders. Some of these threads update status Views as well.
Since I am new to Android, the application framework model hasn't clicked for me. Where are these threads started? Right now I start the threads in the initial Activity, but if I understand it right, once that Activity goes invisible it is stopped. Furthermore, I have to track GPS and network statistics so that I can have a View which may (or may not) be the active View.
View 1 Replies
View Related
Aug 30, 2009
In the following sequence of events:
1. Start a new thread (as a result of a button click - or similar).
2. User changes the screen orientation (causing the Activity that started the thread to be destroyed).
3. Thread finishes, and wants to do some dialog (or any UI) work. However, doing a showDialog, dismissDialog, ... will crash, as the thread it still referring to the old Activity.
This can be solved by updating the data in the thread to refer to the new Activity upon a screen orientation change.
However, couldn't the Android framework just forward any requests from a destroyed activity, to the newly created Activity, saving us developers of handling it ourselves?
View 24 Replies
View Related
Mar 18, 2009
I was wondering, why there is no functionality to pin threads a user is interested in. As there is such a high traffic on these groups, it takes time to find the threads I answered to or some I am interested to see how the problem is solved. Sometimes you don't remember the naming of the subject or the user that wrote it and then searching becomes annoying. An easy way would be to pin some threads! I mean the right side is nearly empty an everybody is authenticated when she uses the group, not to just read.
View 7 Replies
View Related
Sep 22, 2010
Are there any limits on the number of threads or any constraints on how the emulator (under Eclipse) schedules the application threads? I get suspended threads that don't really wait on anything but rather get bumped out from execution time. I will try using the Debug class to get some statistics on the thread alloc etc. even though the DDMS does that already. One example is, I have a simple class that simply prints a '.' every 3 seconds - well, the LogCat shows the emulator collecting garbage objects but the thread is suspended and does not print the '.'
View 7 Replies
View Related
Aug 25, 2009
I would like to know how to run a listener on an isolated thread. Because I would like to use a LocationListener and make some calculations in the main thread. So the LocationListener would be "slow down", because of those calculations. Is it possible to have it run in a different thread? Or is it by default in a separate thread?
View 2 Replies
View Related
Sep 7, 2010
I want to create one method and call the created Thread inside that method in my Android Application, I am new to Java as I had told before. Can anybody giive me an example of how should I create a method and call a Thread inside that method!
View 2 Replies
View Related
Jul 3, 2010
I am starting to develop an Android App and have noticed the following behaviour in my test code (not yet designed the real app):
A thread that loops around doing Bluetooth IO accesses an instance variable that is declared in the enclosing class. That instance variable gets set to null by the GUI thread in the onBackPressed() method which also closes the Bluetooth socket which causes an exception in the IO thread (which is what I want).
The odd thing is that if I set the instance variable to null before I close the socket, the IO thread sees the null value, but if I close the socket first and then set the variable to null, the IO thread doesn't see the null value.
The instance variable is being used in a loop in the IO thread and it appears as if that variable is being cached while within the loop. So any changes to that variable by another thread are not visible. Is that possible? If so, is there a workaround to guarantee that the VM will read the value of the instance variable?
View 4 Replies
View Related