简体   繁体   English

通过使用标志一次显示AlertDialog

[英]Show the AlertDialog once by using flag

I am sending data route,long, lat, mac to the Server very 10 seconds. 我要在10秒钟之内将数据路由,long,lat,mac发送到服务器。 Often the route is 0. In this case, the server will be asked for the route. 路由通常为0。在这种情况下,将要求服务器提供路由。 As soon as the app has the route from the server , Checkbox AlertDialog appears to confirm the result by the user. 一旦应用具有从服务器AlertDialog的路由, AlertDialog出现“复选框AlertDialog ”,以确认用户的结果。 Then the route will be envloped with the other data Long, lat, mac as JSOn string and transmitted to the server again. 然后,该路由将被其他数据Long,lat,mac JSOnJSOn字符串,并再次传输到服务器。

I am facing Problem that the alert Dialogs will pile up when the user does not interact with the Dialog immediatly. 我面临的问题是,当用户不立即与对话框交互时,警报对话框会堆积。 What I am trying to achieve is to pop up the Dialog window just once when the server provides the app with route and not very 10 seconds with the Response from the server since when the user reacts too late he has to confirm all these Dialog Windows also after 1 Minute he has to confirm 6 Dialog Windows. 我要达到的目的是,当服务器为应用程序提供路线时仅弹出一次Dialog窗口,而从服务器的响应中弹出的时间不是10秒,因为当用户反应太晚时,他还必须确认所有这些Dialog Windows。 1分钟后,他必须确认6个对话窗口。 Therefor, I am using flag to reach that but the problem currently with flag is when it is set once to false it is not possiable to enter the stop_popup method again till the app is restarted gain. 因此,我正在使用flag来实现这一点,但是标志的当前问题是,一旦将其设置为false,就无法再次输入stop_popup方法,直到应用重新启动。

Is there anyway to set the flag variable to true after 10 minutes without interupting sending the data to the server? 无论如何,是否会在10分钟后将flag变量设置为true,而不会中断向服务器发送数据?

public class TrackingService extends Service implements AsyncTaskCallback  {

    boolean flag = true;
      ......
        @Override
    public void onAsyncTaskFinished(ArrayList<Integer> routeList, double distance) {
        if (distance <= 15 && speed <= 4 && flag== true) {
            popup_dialog(routeList);

        } else {
            route_number = routeList.get(0);
            System.out.println("The route number is: " + route_number);
        }

    }


    private void popup_dialog(final ArrayList<Integer> routeList) {


        int routeListSize = routeList.size();
        flag = false;

        if (routeListSize > 0) {
      //AlertDialog.Build code
   }
  }
}

Use a postDelayed Handler that turns flag = true after 10 minutes. 使用postDelayed Handler ,该Handler程序在10分钟后变为flag = true

private void popup_dialog(final ArrayList<Integer> routeList) {
    int routeListSize = routeList.size();

    flag = false;

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            flag =true;                       
        }
    }, 10 * 1000 * 60);  // 10 minutes (60 sec * 1000 milliseconds)

    if (routeListSize > 0) {
        //AlertDialog.Build code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM