取消了Runnable在LocationOverlay对象的.runOnFirstFix()方法 [英] Cancel the Runnable in the .runOnFirstFix() method of LocationOverlay Object

查看:184
本文介绍了取消了Runnable在LocationOverlay对象的.runOnFirstFix()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有地图功能的应用程序的大量斜靠。从第一次活动我称之为 runOnFirstFix()方法,一旦用户的位置已经发现,从数据库中装载了大量的数据,但我也希望能够打断这个可运行和停止执行中期,当我切换活动或用户presses按钮停止运行它。

I have an application the leans heavily on map functionality. From the first Activity I call the runOnFirstFix() method to load a lot of data from a database once the location of the user has been found, but I also want to be able to interrupt this runnable and stop it mid execution for when I switch activity or the user presses the button to stop it running.

myLocationOverlay.runOnFirstFix(new Runnable() {
            public void run() {
                mc.animateTo(myLocationOverlay.getMyLocation());
                mc.setZoom(15);
                userLatitude = myLocationOverlay.getMyLocation().getLatitudeE6();
                userLongitude = myLocationOverlay.getMyLocation().getLongitudeE6();
                userLocationAcquired = true;
                loadMapData();  //Here the method is called for heavy data retrieval    
            }
        });

我怎样才能阻止这种Runnable的执行中期?

How can I stop this Runnable mid execution?

推荐答案

使用handler对象来处理这个运行的。

use the handler object to handle this runnable.

定义这个可运行在Runnable对象。

define this runnable with the runnable object.

之后,在处理程序即可启动取消该服务,可运行

after that in handler you can start the cancel this runnable service

有关如

Handler handler = new Handler();

在启动命令()

handler.postDelayed(myRunnable,5000);

这将在5秒之后执行的可运行的run方法

this will execute the run method of runnable after 5 sec

有关取消

handler.removeCallbacks(myRunnable);

和您可运行这样定义的方式

and your runnable define like this way

private Runnable myRunnable = new Runnable(){
      public void run(){
          // do something here
      }
}

http://developer.android.com/reference/android/os/ Handler.html

http://developer.android.com/reference/java/ UTIL /日志/ Handler.html

http://www.vogella.de/articles/AndroidPerformance/article.html

这篇关于取消了Runnable在LocationOverlay对象的.runOnFirstFix()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆