Android Question Unexpected Activity_Pause

GaryK4

Member
Licensed User
Longtime User
I have a landscape only application. At times when I start a new activity (form), it kicks back to the main activity with UserClosed = false.
I don't know what is causing this or how to debug it. I am not hitting the back button or the home button. If I hit the button (tab) to go back into the activity, everything works. I display a ToastMessageShow when this happens and UserClosed = false.
Any ideas what to look for or how to debug it?
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
What is in the Activity_Create that you are attempting to start? It's it possible that nothing is being loaded and therefore the focus is returning to the calling Activity?
 
Upvote 0

GaryK4

Member
Licensed User
Longtime User
What is in the Activity_Create that you are attempting to start? It's it possible that nothing is being loaded and therefore the focus is returning to the calling Activity?

I am doing a LoadLayout of a Mapfragment. It also initializes GPS. This is a Golf app. I have GPS running in the main activity and again in the map activity.
Everything seems to load fine. I see the golf hole and pin marker. Then after 3-5 seconds, it exits to the main activity without touching anything. When I go back to the map after being kicked out, it stays. This does NOT happen all the time which makes it more confusing.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
What do you have in the main activity? Could an event be triggering it to return to the front?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Result of a Httpjob for ex.
 
Upvote 0

GaryK4

Member
Licensed User
Longtime User
Result of a Httpjob for ex.

I think this may be the case, but I am a little confused. I had to restart GPS in the map activity because it was not updating when I went from the main to the map activity. So, I thought the main was dormant while the map activity was running. Is HTTP a service running in the background until complete?

I can change my program to work around this.
Any other possible triggers off the top of your head?

Thanks for all the help.
 
Upvote 0

GaryK4

Member
Licensed User
Longtime User
Move any code not related to the UI to a service. See the GPS tutorial for an example.

OK, I put the GPS code into a service and it appears to work well.
One question: In the (2) UI's that need the GPS data, I created timers to replace the GPS_LocationChanged subs. The timers look at variables in the service Process_Globals. Is this an ok approach?

Service variables
B4X:
Sub GPS_LocationChanged (inpLoc As Location)
    gps.cur_location = inpLoc
    gps.last_update =  DateTime.now
    gps.location_changed = True
End Sub
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Your solution looks like a good solution to me! :)

The other way you could do it is to call a Sub from the Service. This way you would only be running the routine when the LocationChange event was triggered.
To do this you would need to know which Activity is running either by storing and updating a Global variable or by asking the system...
https://www.b4x.com/android/forum/threads/get-the-current-activity-from-a-code-module.68666/

I think that maybe your solution is the simplest, which is normally my preferred choice. Keep it simple so it's easier to debug. :D
 
Upvote 0

GaryK4

Member
Licensed User
Longtime User
Your solution looks like a good solution to me! :)

The other way you could do it is to call a Sub from the Service. This way you would only be running the routine when the LocationChange event was triggered.
To do this you would need to know which Activity is running either by storing and updating a Global variable or by asking the system...
https://www.b4x.com/android/forum/threads/get-the-current-activity-from-a-code-module.68666/

I think that maybe your solution is the simplest, which is normally my preferred choice. Keep it simple so it's easier to debug. :D

In my timer routines, I check (if gps.location_changed = False then return). That get close to the LocationChange event was triggered.

I like simple also. I avoid black belt difficult to read code.
 
Upvote 0
Top