Hi!
Just have a Problem with stopping a thread by finishing a programm
through
- just go back to mainmenu or go back with the back button.
It is replying always on in the Log modul the data.
My programm catches the Location data from the GPS modul and should
send it to a webservice. But when the home button or the back button
is pressed the threads are always going on ... and telling the thread
that there is an interrupt for him doesn't make anything.
Has anybody an idea why it's always running?
I tried to implement another method in the thread class called stop
this method set an boolean to true and the while loop is then set to
this boolean variable but from outside i can't set the variable to a
diferent state because he can't get the function or variable in the
inner class ....
My code is:
Java:
import com.google.android.maps.Point;
import com.google.googlenav.map.MapPoint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
public class MyData extends Activity {
private Thread thread = null;
private MyLocation myloc = null;
private MapPoint mp;
private GraphicsView graphicsview = null;
private Context context;
protected static final int GUIUPDATEIDENTIFIER = 0x101;
public int counter=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
context = this;
super.onCreate(icicle);
graphicsview = new GraphicsView(this);
setContentView(graphicsview);
init();
}
private void init(){
Runnable runnable = new thread();
thread = new Thread(runnable);
thread.start();
}
public void onDestroy(){
this.thread.interrupt();
finish();
}
public void finalize(){
this.thread.interrupt();
finish();
}
Handler myViewUpdateHandler = new Handler(){
// @Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MyData.GUIUPDATEIDENTIFIER:
//Do the update / refresh stuff
// Get the GPS information and set them to
myactualposition
myloc = new MyLocation(context);
mp = myloc.getmyLocation();
Log.d("mydata", "I'm in the Handler doing
submission "+counter);
Log.d("mydata", "GPS Object: "+mp.toString());
graphicsview.setBackground(123455);
graphicsview.invalidate();
counter++;
break;
}
super.handleMessage(msg);
}
};
class thread implements Runnable {
// implements Runnable ....could be done if you want to have
more threads access on a object
public boolean testat = false;
/*
* Starts the thread and makes a Message so that a Handler
can get it.
* Done because only the initialiesed thread could make a
update so a Handler is needed
* see also picture at
http://www.anddev.org/instantmessaging_display_incoming_messages_without_action-t162.html
* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
// @Override
public void run() {
while(!Thread.currentThread().isInterrupted()) {
Message m = new Message();
m.what = MyData.GUIUPDATEIDENTIFIER;
MyData.this.myViewUpdateHandler.sendMessage(m);
try {
Thread.sleep(10000);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---