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:
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