Estoy tratando de lanzar y alertar al diálogo sobre el subproceso de la interfaz de usuario desde mi hilo de fondo, pero tengo problemas con la ejecución de undeOnUiThread. He intentado FindLocation.this.runOnUiThread
y runOnUiThread, pero ambos parecen lanzar el mismo error The method runOnUiThread(new Runnable(){}) is undefined for the type new LocationListener(){}
(o ...the type FindLocation
). ¿Alguna idea de por qué? Aquí hay un fragmento de mi clase FindLocation.java. Esto es llamado por mi actividad principal.runOnUiThread Indefinido para la clase
public class FindLocation extends Thread {
public boolean inJurisdiction;
public boolean AlertNotice = false;
private LocationManager locManager;
private LocationListener locListener;
Context ctx;
public String userId;
public FindLocation(Context ctx) {
this.ctx = ctx;
}
public void start(String userId) {
this.userId = userId;
super.start();
}
@Override
public void run() {
Looper.prepare();
final String usr = userId;
//get a reference to the LocationManager
locManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
//checked to receive updates from the position
locListener = new LocationListener() {
public void onLocationChanged(Location loc) {
String lat = String.valueOf(loc.getLatitude());
String lon = String.valueOf(loc.getLongitude());
Double latitude = loc.getLatitude();
Double longitude = loc.getLongitude();
if (latitude >= 39.15296 && longitude >= -86.547546 && latitude <= 39.184901 && longitude <= -86.504288 || inJurisdiction != false) {
Log.i("Test", "Yes");
inJurisdiction = true;
FindLocation.this.runOnUiThread(new Runnable() { ///****error here****
public void run() {
AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
alert.setTitle("Sent");
alert.setMessage("You will be contacted shortly.");
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
}
});
eso es porque 'runOnUiThread' es de' android.app.Activity', no 'java.lang.Thread' – Vladimir
Shoot. ¿Hay alguna manera de implementar algo similar? – mkyong
@Alex He agregado una respuesta – Vladimir