Android Question SMB: Works in Activity A but not in activity B

Robert Bussey

Member
Licensed User
Longtime User
So, I'm missing something and have no idea what. Many, many hours of research has proven fruitless.

The issue: There are multiple activities in my project, two of them use SMB. In one the SMB works perfectly. In the other SMB will not initialize. The code is absolutely identical in both instances. The Activity where it works is not the "Main" or startup activity. The startup activity is the one SMB does not work in.

It has to be something simple. Help save my sanity.......

Cheers,
Bob
 

mangojack

Expert
Licensed User
Longtime User
So, I'm missing something and have no idea what. Many, many hours of research has proven fruitless.
Bob

Welcome Bob .. It would be best if you could upload your project or a small test sample highlighting the problem.
IDE menu > File > Upload as zip.
 
Upvote 0

Robert Bussey

Member
Licensed User
Longtime User
Here it is:
lastexception gives up "Not initialized" on the one that does not work.
Thank you so much for taking a look!

B4X:
'
' the activity that does not work
'
Sub Globals  
Dim Cursor As Cursor   
Dim SQL1 As SQL  
Dim lstAuthor As ListView   
Private lblStitle As Label   
Dim SMB As SMB   
Dim sFile As SMBFile
Dim Path as string
End Sub
'
Sub Activity_Create(FirstTime As Boolean)
If FirstTime=True Then
   Activity.LoadLayout("BookList_Main")
   ReloadAuthors=True
   Activity.AddMenuItem("Check for DB Update","mnuCheckSMB")
   Activity.AddMenuItem("Show Books.db local path","mnuShowPath")
   Activity.AddMenuItem("Title Search","mnuSearch")
   Activity.AddMenuItem("Want to Read List","mnuWanttoRead")
   Activity.AddMenuItem("Add Titles","mnuAddTitles")
   Path="smb://192.168.1.1/USB_Storage/eBooks/" 
   SMB.Initialize("SMB1")
   SMB.listfiles(Path,"")
   If ReloadAuthors=True Then LoadAuthors
End If 'firsttime
End Sub
'
'
'
' the activity that does work
'
'
'
Sub Globals
Dim SMB As SMB
Dim SQL As SQL
Dim dCursor As Cursor
Dim Parser, ParseD As SaxParser
Dim xFlag As Boolean
.
.
.
End Sub
Sub Activity_Create(FirstTime As Boolean)
 
If FirstTime=True Then
     Activity.LoadLayout("BookList_NewTitles")
     Label1.SetLayout(btnBack.Left+btnBack.Width+4,0,100%x-btnBack.Width,btnBack.height)
     ListView1.SetLayout(0,btnBack.top+btnBack.Height+4,100%x,100%y-btnBack.Height-10)
     SMB.Initialize("SMB")
     SMB.ListFiles("smb://192.168.1.1/USB_Storage/eBooks/","")
     Label1.Text="smb://192.168.1.1/USB_Storage/eBooks/"
     Parser.Initialize
     ParseD.Initialize
'
End If

End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Here it is:
lastexception gives up "Not initialized" on the one that does not work.

Moving all SMB initialization and startup code to a Starter service will most likely solve this problem ..

see THIS ...
 
Last edited:
Upvote 0

corwin42

Expert
Licensed User
Longtime User
You are using "FirstTime" variable wrong. See the Activity life cycle tutorial and the tutorial about the starter service.

Doing Loadlayout inside a FirstTime if block is totally wrong.
 
Upvote 0

Robert Bussey

Member
Licensed User
Longtime User
Issue resolved by removing SMB from the main activity where it did not work into a new activity where it does. The new activity was needed anyway due to very poor UI design. Thanks again for the constructive comments. They are always appreciated.
 
Upvote 0
Top