On Apr 1, 10:34 am, Streets Of Boston flyingdutc...@gmail.com wrote:
Do *not* use volatile variables. They are not guaranteed to be atomic.
It's just a compiler hint.
Thanks for the tip.
--~--~-~--~~~---~--~~
You received this message because you are subscribed
Try this:
Create a set of volatile variables (toPause, isPaused, toStop,
isStopped).
Outside the thread, in the methods mentioned previously, set or clear
the appropriate variables.
Inside the thread, be checking the appropriate variables to determine
if the thread needs to be paused or
Do *not* use volatile variables. They are not guaranteed to be atomic.
It's just a compiler hint.
Instead, use synchronized blocks:
class MyThread extends Thread {
boolean mPaused;
boolean mStopped;
public void run() {
...
...
mStopped = false;
mPaused = true or false,
Thank you, I will try to implement this when I have time. I now
understand where my confusion was stemming from. I was under the
impression that each time the CupView Activity was resumed, a new
CupView object was created thus creating a new CupThread. However I
now see that is not the case, the
I don't think you've included enough code. Where is this 'thread' variable
defined? Where do you clear it after finishing the thread?
I am also confused by the comment saying you exiting the activity in
rollDice -- you aren't calling finish, you are just starting another
activity, so the
This is where the thread variable is declared.
private Context mContext;
/** The thread that actually draws teh animations. */
private CupThread thread;
private TextView mStatusText;
public CupView(Context context, AttributeSet attrs){
This is the main Activity of my app. The one holding a CupView.
package my.package;
import my.package.CupView.CupThread;
import org.openintents.hardware.SensorManagerSimulator;
import org.openintents.provider.Hardware;
import android.app.Activity;
import android.content.Intent;
import
This is the CupView Class.
package my.package;
import org.openintents.hardware.SensorManagerSimulator;
import org.openintents.provider.Hardware;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import
I haven't read through all your code, but you should not call
thread.start() in your surfaceCreated method.
Instead, create and start your thread asap and have it paused when
necessary.
When 'onPause()' or when surfaceDestroyed is called, pause your thread
(CupThread).
When 'onResume()' or
Thank you for your suggestions, however according to the API, there is
no way to pause or resume threads. Only start them, then join them
(which eventually kills it). All related methods for pausing and
resuming have been deprecated it seems.
On Mar 31, 11:07 pm, Streets Of Boston
10 matches
Mail list logo