Activity_resume

dmtulsa

Member
Licensed User
Longtime User
I've read the beginners guide about Activity_resume & Activity_pause but I'm not sure how to put it into practice. What exactly do I need to save in Activity_pause if I go to another app then want to come back to where I was at?

For example, in the code below I log onto a windows server and can drill down to a directory and file. Say I select a .PDF the I open Adobe reader to show the file. When I finish with Adobe( go back) my File utility activity is blank.

Do I need to put Activity..LoadLayout(xxxx) in Activity_resume? if so then what do I have to save (How) in Activity_pause to get back to the exact point I left it?

I assume I would do the same think for screen rotation.

Thank you
Doug

CODE:
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim usismb As SMB
   Dim timer1 As Timer
   Dim PathRoute As Map
   'Type smbFileData(name As String,isDirectory As Boolean, Parent_URL As String)
   'Dim dIndex As Long
   'Dim FileData(dIndex) As smbFileData
   
   

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim btnfiles As Button
   Dim timerFlag As Byte
   Dim lbl_Path As Label 
   Dim lv1 As ListView
   Dim lastDir As String
   Dim j As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   If FirstTime Then
       Activity.LoadLayout("Manuals")
      usismb.SetCredentials("tech","tech","Avionics")
      usismb.Initialize("usismb")
      timer1.Initialize("Timer1",1000)
      
   End If
   
   
   
End Sub

Sub Activity_Resume
  Activity..LoadLayout("Manuals")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Timer1_Tick
'if working on long task enable timer
 Select timerFlag
    Case 0
        lbl_Path.Text = "Please Wait"
       timerFlag = 1

   Case 1
       lbl_Path.Text = "Working on it"
       timerFlag = 0
 End Select   
 
End Sub

Sub usismb_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
Dim title As String,fileEx As String
Dim x As Int

   If Not(Success) Then 
        Log(LastException)
       timer1.Enabled = False 
      lbl_Path.Text = "Error, See Enginering"
   Else
       timer1.Enabled = False
      lbl_Path.Text = lastDir
      lv1.Clear 'clear listview of entries
      For i = 0 To Entries.Length - 1            'read all dir's / files in path as per ListFiles
         If Entries(i).Directory = True Then     'if true then its a directory
         title = Entries(i).Name.SubString2(0, Entries(i).Name.Length-1)
         lv1.AddTwoLinesAndBitmap( Entries(i).Name,"",LoadBitmap(File.DirAssets, "folder.png"))
      Else
         x = Entries(i).Name.Length-1
         Do While Entries(i).name.charat(x)<>"." AND x>0 'find .
            x = x - 1                            
         Loop
         fileEx = Entries(i).name.SubString(x + 1) 'file extinition         
         title = Entries(i).name.SubString2(0,x)      'file name      
         If fileEx = "pdf" Then
              lv1.AddTwoLinesAndBitmap(title & ".pdf","",LoadBitmap(File.DirAssets, "file_PDF.png"))
         End If   
      End If   
      Next
      
   End If
End Sub


Sub btnFiles_Click
    'User clicks to set initial search params

   timerFlag = 0
   timer1.Enabled = True
   btnfiles.Enabled = False
   PathRoute.Initialize
   lastDir = "smb://10.0.0.1/users/manuals/"
   j = 0
   PathRoute.Put(j,lastDir) 'route(0) = root path
   usismb.ListFiles(lastDir,"") 'get list of driectoy
   
   
End Sub
Sub LV1_ItemClick (Position As Int, Value As String)
Dim fex As String, x As Int,tmpdir As String,ret As Boolean

If Value.charat(Value.Length-1)="/" Then    'thanks to stu for some sample code **
    lastDir = lastDir & Value
    j = j + 1
    PathRoute.Put(j, lastDir)
    usismb.ListFiles(lastDir,"")
Else
   x = Value.Length -1
   Do While Value.charat(x) <> "." AND x > 0 'find .
      x = x - 1                            
   Loop
   fex = Value.SubString(x + 1)'**
   If fex = "pdf" Then
      Dim nom_file As String
      'nom_file = "file:///sdcard/_lelong/fiches_tarif/" & nomdoc
      nom_file = lastDir & Value
      tmpdir = File.DirRootExternal & "/UsiManual/"  ' File.DirInternalCache
      ret = File.Exists(tmpdir,Value)
      If ret = False Then usismb.DownloadFile(lastDir,Value,tmpdir,Value)
            
      ''Msgbox(nom_file,"nom fichier")
      nom_file = "file:///" & tmpdir &  Value
      Dim zz As Intent 'Requires a reference to the Phone library
      zz.Initialize(zz.ACTION_VIEW, nom_file)
      zz.SetType("application/pdf")
      'zz.WrapAsIntentChooser("Choose PDF Viewer")
      StartActivity(zz)
    End If
End If
End Sub
Sub bntBack_Click
'**
       If j>0 Then 'thanks to stu for some sample code
        usismb.ListFiles(PathRoute.Get(j-1),"")
        lastDir = PathRoute.Get(j-1)
        PathRoute.Remove(j)
        j=j-1
    End If
'**   
End Sub
 

NJDude

Expert
Licensed User
Longtime User
You have a couple of issues:

B4X:
...

If FirstTime Then

    Activity.LoadLayout("Manuals")
    usismb.SetCredentials("tech","tech","Avionics")
    usismb.Initialize("usismb")
    timer1.Initialize("Timer1",1000)

End If
 ...
By doing that, you are loading the layout and doing the initializations, etc ONLY when the app runs for the VERY FIRST TIME, you should not put that code in "FirstTime"

B4X:
Sub Activity_Resume
    Activity..LoadLayout("Manuals")
End Sub
This is not neccessary.

Make those changes and then try your app again.
 
Upvote 0

dmtulsa

Member
Licensed User
Longtime User
Thanks,

Commenting out "If FirstTime Then" solved the problem about coming back to a blank screen. It now comes back as if it started all over which I suppose it has. Is there a proper / correct way to save to state exactly as it was? Lets say I had drilled down two levels into the server directory then I leave to show a .pdf how do I get back to that state and not back to the start of the program.

I think I can make it do what I want but I doubt it would be pretty or the correct way to do it.

Thank you again
Doug
 
Upvote 0

dmtulsa

Member
Licensed User
Longtime User
The State manager looks like a very cool tool. To bad it doesn't have ListView view as an object to save or restore to in ver 1.1 of the .bas
Can a listview object just be added to the statmanager.bas?

Thanks again
Doug
 
Upvote 0

dmtulsa

Member
Licensed User
Longtime User
Ok thank you. I guess I need to rethink this and study more about how activities work. I've read your tutorial but now I better study it.

Doug
 
Last edited:
Upvote 0
Top