runnable

How does one implement a truly asynchronous java thread

I have a function that needs to perfom two operations, one which finishes fast and one which takes a long time to run. I want to be able to delegate the long running operation to a thread and I dont care when the thread finishes, but the threads needs to complete. I implemented this as shown below , but, my secondoperation never gets don...

Sockets, Threads and Services in android, how to make them work together ?

Hi all, I am facing a probleme with threads and sockets I cant figure it out, if someone can help me please i would really appreciate. There are the facts : I have a service class NetworkService, inside this class I have a Socket attribute. I would like it be at the state of connected for the whole lifecycle of the service. To conne...

Simple Android Binary Text Clock

Hello, I want to create a simple android binary clock but my application crashes. I use 6 textview fields: 3 for the decimal and 3 for the binary representation of the current time (HH:mm:ss). Here's the code: import java.text.SimpleDateFormat; import java.util.Calendar; import android.app.Activity; import android.os.Bundle; import an...

Do I need a semaphore for my thread in Android/Java?

Hello all, When running a thread in Android/Java: public void run() { while (running) { if (moreTasksToExec()) { task = getNextTask() task.exec(); } } } Is it OK to let it run and not using a semaphore to block while no work needs to be executed? I am only using one thread, so I need no ...

Android - Question on postDelayed and Threads

I have a question about postDelayed. The android docs say that it adds the runnable to the queue and it runs in the UI thread. What does this mean? So, for example, the same thread I use to create my layout is used to run the Runnable? What if I want it as an independent thread that executes while I am creating my layout and defining ...

Update JProgressBar

I can't update my progressbar... this is my code Thread t=new Thread(new Runnable(){ public void run(){ int i=1; jProgBar.setMinimum(0); jProgBar.setMaximum(100); try { while(i<=100 || true){ jProgBar.setValue(i); i++; ...

Creating a skeleton for a Game Algorithm in Android

Hello. I need some help on the following: I have the following class: public class Game extends Activity {... ...} My questions is: Where and how do I create my View (do I use another class that extends View....) Where and how do I implement the Runnable interface so I would be able to use threads. Where and how do I connect all...

Run method from extends Activity extends Runnable

I'm trying to call a method from inside a Runnable that is running. It waits for a string to be entered and when it is then depending on the string (the strings act as commands) it calls a method and is supposed to run whats inside it. public class App extends Activity implements Runnable { public void run() { try { Ser...

optimizing bitmap loading by using aSyncTask.

I have been trying to optimize my single thread app which loads a bunch of tiles that makeup a large bitmap. The app was becoming very sluggish when it would load the new tiles into system memory. Im now looking trying to use Async Tasks for this purpose. The app detects which tile is in the top left in a method called by onDraw, creates...

Retrieving a String out of a runnable/TimerTask

Hello I have implemented a timer that parses a URL every 15min (the Timer task). An Object that i have created gets that data .I use it afterwards to display the data on the screen . Now , whenever i try to retrieve that Object/a String=Object.toString() out of the runnable I get null pointer exception and fatal errors . My questio...

Queue Threads if previous ones haven't finished

Hi, I'm trying to write a simple video manipulator, so several times a second I need to start a new thread (currently implementing Runnable) to process the current frame but I have no guarantee how long each thread will take to finish and as such I want to limit the number of threads that can run at once to the number of processors on...

Get Object out of a method(runnable) , timer

Hi Guys, I have implemented a timer that parses a URL every 15min (the Timer task). An Object called ParsedExampleDataSet gets that data . Now , whenever i try to retrieve that Object or a String=Object.toString() out of the runnable I get null pointer exception and fatal errors . How Can i retrieve it ?Is there another implementatio...

How to remove a runnable from a handler object added by postDelayed?

Hi, I have an "open" animation and am using Handler.postDelayed(Runnable, delay) to trigger a "close" animation after a short delay. However, during the time between open and close, there is possibly another animation triggered by a click...my question is, how would I cancel the "close" animation in the handler? Thanks ...

Is this thread safe?

I am writing an application for Android and am using worker threads to process certain information. Having read through my code I am now unsure if it is thread safe. I have written a simplified version of my code, I have omitted the Handler object used to communicate with the main thread and obviously the process itself. public class m...

Creating a runnable JAR which includes .exe files via eclipse

Hey guys - I've looked through a plethora of forums online as well as asked many professional java developers but I was unable to find adequate assistance in creating a standalone runnable jar file of a financial application that I am currently finishing up. The application uses two external programs; an ImageMagick file conversion progr...

android:Handler from a Runnable throws Null Pointer Exception

I have a Thread that downloads data from internet public class Bp implements Runnable { Handler myHandler; public void setHandler(Handler myHandler) { this.myHandler=myHandler; } .... myHandler.sendEmptyMessage (0); } There is an activity that needs to be updated according to downloaded data. public class Hp extends Activity impleme...

Help with implementing Runnable in Java

Hello StackOverflow. I'm working on a java project with my team at work. To summarize, we have a main class that has a method that instantiates and calls a "Save" class. This "Save" class saves files back to a server with a couple of constructors and a handful of visible and non-visible methods. The class is CPU-intensive and time-...

Java interface question

I'm confused (new to java): When implementing the Runnable interface, one must override the run() method to get thread execution capability. Implementing this interface makes your object a type Runnable (?). How does the thread functionality get "injected" by simply implementing the Runnable interface? Basically when you instantiate ...

Cannot figure out the context when launching an Intent from within a thread completion method

I am trying to launch a new intent after I have loaded data. I am using a handler that calls a method when the thread is complete and then in this method I am trying to launch a new Intent but my app is crashing every time. I have narrowed it down to the Context variable in the Intent constructor. Here is my code: /** Called when the...

Context inside a Runnable

Hi, I try to play a sound from R.raw. inside a Thread/Runnable But I can't get this to work. new Runnable(){ public void run() { //this is giving me a NullPointerException, because getBaseContext is null MediaPlayer mp = MediaPlayer.create( getBaseContext(), R.raw.soundfile); while (true) { if (somethin...