Android Question app DOES NOT RESPOND dialogue

Discussion in 'Android Questions' started by peacemaker, Mar 2, 2015.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    I have found that recent months my apps (mostly using HttpUtils2) after start in several seconds are followed by the "app does not respond" system dialog.
    In long FOR loops i always use the code like
    Code:
    If (i mod 100) = 0 then DoEvents
    B4A is always latest actual (now v.4.3), but test devices are the same recent years (see my signature).

    But now in app template with the service working with the accelerometer, without loops and DoEvents it has occured also :-(

    Erel, full source code is emailed to you.
    Any help ?

    Team, did you have such issue recent 2-3 years (at least with apps using HttpUtils2) ?
     
  2. DonManfred

    DonManfred Expert Licensed User

    Using DoEvents is not a solution.
    The solution will be using Threads and/or Async tasks for longer loops. Maybe a service.
     
  3. peacemaker

    peacemaker Well-Known Member Licensed User

    This time the service has only
    Code:
    Sub Service_Create
    others.Notif(
    "Started OK."FalseFalse, Main, "")
    Service.StartForeground(8, Notif1)

    Try
        sensor.Initialize(sensor.TYPE_ACCELEROMETER)
        AccelExists = 
    True
    Catch
        AccelExists = 
    False
        
    ToastMessageShow("No accel: stopped"True)
        
    CallSub(Main, "Activity_Close")
        
    StopService(Me)
    End Try
    End Sub

    Private Sub Sensor_SensorChanged (Values() As Float)
    SensorX1 = 
    Round(Values(0)) * 10
    SensorY1 = 
    Round(Values(1)) * 10
    SensorZ1 = 
    Round(Values(2)) * 10
    End Sub
    sensor.StartListening("Sensor") is used separately, by an interface button
     
    Last edited: Mar 2, 2015
  4. Erel

    Erel Administrator Staff Member Licensed User

    The first step is to remove all the DoEvents calls. They will only cause problems.

    HttpUtils2 doesn't block the main thread and will not cause such an error.

    You need to find out which part of the code blocks the main thread.
     
  5. peacemaker

    peacemaker Well-Known Member Licensed User

    Clear, but this app with accelerometer without HttpUtils2 ? (i emailed the full source)
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Try to reproduce it in a small project and upload the project.
     
  7. peacemaker

    peacemaker Well-Known Member Licensed User

    Indeed - DoEvents was the issue...
    Solved.
    Do not use DoEvents at service start.

    But how to be sure correctly that a service is started, all initialized, database is opened.... before letting the user to work with the activity ?
    In big app it's needed long time for whole initializations.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Are you starting the service when the activity is created? You can use CallSubDelayed to call a sub in the activity from the service when everything is ready.
     
  9. peacemaker

    peacemaker Well-Known Member Licensed User

    Yes, from activity, but activity interface depends on the service work, that should be inited first, for rather long time.
    Thanks for suggestion.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice