2 subs stacks in the same activity

Ramirez

Member
Licensed User
Longtime User
Hello.
I have a problem with my application.
If I wrote :
B4X:
Sub Activity_Resume
   If variable="" Then StartActivity("User")
   Activity.Title = "FlexiPoint - " & variable
   MiseAJourTable
End Sub
(Whe are in the Main activity, MiseAJourTable is another sub.)

My program make something strange:
1 - the activity User is not called (i am sure that variable="")
2 - the program continue is execution and stop (pause) later in the main activity, in the MiseAJourTable sub
3 - after few seconds, the screen of the mobile device become black (not turn off, just black)

The subs stack indicator (debug mode, left part of the screen) indicate that in the Main activity, I have 2 subs "activated", first is the MiseAJourTable sub, the second is the Activity_resume sub (or in the other order, I don't remember exactly. If it's important, I can confirm that later).

If i wrote :
B4X:
Sub Activity_Resume
   If variable="" Then 
      StartActivity("User")
   Else
      Activity.Title = "FlexiPoint - " & variable
      MiseAJourTable
   End If
End Sub

the program works but not exactly like my desire:the MiseAJourTable must be called at each resume of the activity.

I don't understand my mystake. Could you help me please ?

thx
 

Attachments

  • program.zip
    31.3 KB · Views: 186

Ramirez

Member
Licensed User
Longtime User
Hello NJDude, thanks for fast reply.

I try to remove quotes but result is the same :sign0013:

I think that the stack is correct: the sub MiseAJourTable is called by the sub Activity_resume, so I suppose that's normal to saw the 2 sub in the stack.

But I don't understand why the activity 'User' is not called ! I try to move the call in the activity_create sub, but result are same !

I have another question, when an activity is called by the activity_resume sub, when the called activity is closed, what's happen exactly ? Is the program return to the activity_resume calling point ? Is the activity_resume restart another time (so 2 occurences exist in the memory of the phone) ?...
It's not clear for me and maybe my problem is cause by this misunderstanding.
(I don't know if this word exist, I'm French and hope you understand me ).
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I replied based on what I read on your post, now, I've downloaded you project and you are missing a database "Database.db" you must include it to your project to properly test you app.
 
Upvote 0

Ramirez

Member
Licensed User
Longtime User
The database will normaly be create during the first run. You can find mine attached.
Sorry, but the program is full of bug: I work on it last time 6 month ago and I don't find the latest version :BangHead:

Thanks again for help.
 

Attachments

  • Database.zip
    1.1 KB · Views: 193
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
What about

B4X:
Sub Activity_Resume
    If variable="" Then 
        StartActivity("User")
    End If

    Activity.Title = "FlexiPoint - " & variable
    MiseAJourTable

End Sub
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
And if MiseAJourTable HAS to be called eavery resume whether variable ="" or not then swap it around a bit.

B4X:
Sub Activity_Resume

    Activity.Title = "FlexiPoint - " & variable
    MiseAJourTable

    If variable="" Then 
        StartActivity("User")
    End If

  
End Sub

I would also try calling your variable something else. 'variable' could well be a key word that cannot be used.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
For what I could see, the activity named USER is called (after removing the quotes from ALL the StartActivity lines), however is hard to test since you are missing some tables (at least one called AGENDA), unless you haven't incleded that in your project.

This is wrong:
B4X:
    If variable="" Then
         StartActivity("User")
    End If

This is right:
B4X:
    If variable="" Then
         StartActivity(User) '<--- Note there are NO QUOTES
    End If
 
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Yeah, my bad. I copied and pasted original then editted and missed that bit. Us blooody noobs giving out wrong info....

Sent from my HTC Vision using Tapatalk
 
Upvote 0

Ramirez

Member
Licensed User
Longtime User
@ barx
In fact the name of the variable isn't the same than in my soft: I simplify the code to avoid confusion
At the starting of the program, I check if a data is present. If not, I call the 'User' Activity to complete the user data. In fact, it's not necessary to do this check at each time, but the problem occurs too if I put the test and the activity call earlier, in the activity_create for example.
The MiseAJourTable sub is the most important sub: at each return to the main activity I have to refresh data on the screen: that is the function of this sub (MiseAJourTable mean UpdateTable in French )

[edit] after reflexion, it's not really a bad idea to reverse the call of the activity. It's not a "logic" way but possible to run. I will check it.

@NJDude
I understand, for me too, it's difficult to debug all the program. The lastest version work good, but after some month, I don't retrieve it, I have to re-develop the soft with an very old copy. actually, I finish to build the database (3 tables but not all of them at this time).
About quotes, I usually use it and don't have problem. but if you tell that it's not necessary, I will loss this habit to put quote everywhere ( less characters in the soft )

Thanks all for help. I will try to quickly debug my soft and post it here again if problems occurs again.
 
Upvote 0

Ramirez

Member
Licensed User
Longtime User
This is the lastest version of the soft, with the database.
The database file should be put to /sdcard/Android/data/com.flexipoint/files/ directory.
 

Attachments

  • Database.zip
    1.1 KB · Views: 201
  • program.zip
    31.4 KB · Views: 183
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You could add this code to copy the database if doesn't exists
B4X:
If File.Exists(File.DirDefaultExternal, "Database.db") = False Then
            
      File.Copy(File.DirAssets, "Database.db", File.DirDefaultExternal, "Database.db")
                     
End If

also REMOVE THE QUOTES from those lines, look at my previous post.

I'll take a look at he new code and let you know.

EDIT TO ADD: The table named AGENDA is missing, are you sure you have an UPDATED code? please take a look at your files.
 
Last edited:
Upvote 0

Ramirez

Member
Licensed User
Longtime User
Rhaaaaa !!!:BangHead:

Too much mistake for today !

Go to bed.
Tomorow, I will post the good one :sign0013:

good night
 
Upvote 0

Ramirez

Member
Licensed User
Longtime User
OK I'm back less tired I hope don't make same mistakes than yesterday.

I try anything else :

B4X:
Sub Activity_Create(FirstTime As Boolean)
[...]
   Dim curseur As Cursor
   curseur = SQL1.ExecQuery("SELECT * FROM Utilisateur")
   curseur.Position = 0
   If curseur.RowCount = 0 Then 
      StartActivity(User)
   End If
   curseur.Close
End Sub

Sub Activity_Resume
   If Utilisateur <> "" Then 
      MiseAJourTable
   Else
      StartActivity(User)
   End If
End Sub

During the first start, if the database do not have user data, call the activity 'User'. That's OK.
During the activity 'User', if I click on a buton, the data are stored in the database and the name of the user is copy to the variable 'Utilisateur'.
When I return to the Main activity, the Activity_Resume sub is loaded and launch the MiseAJourTable sub. It's OK.

But ...
If I use the back buton of the phone, the program should re-launch the 'User' activity, isn't it ? Because the test of the 'Utilisateur' variable will be false ?

I test this solution step by step, in debug mode and see that:
When I click on the back buton (when I was on the 'User' activity), the program return to the first line of Main Activity_Resume sub. After one step, the test was false ('Utilisateur'="") and the active line become
B4X:
StartActivity(User)
The next step is
B4X:
End Sub
and that's all. The startActivity is completely missing. This "bug" occurs during step by step mode or full running mode.

I am loss :sign0148:
 
Upvote 0

Ramirez

Member
Licensed User
Longtime User
I check in debug mode step by step the starting of the program.
It's strange: each call to another activity isn't do in time. For example, the call of 'User' activity occurs when I was on the resume sub...

I think call activity take a lot of time and the program don't "stop" the running of the sub when call an activity. I don't know if I'm wrong or not but something strange occurs.

So I have another ask: Is it possible to use only one activity and call different layout ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…