Android Question How to make android application into online application?

Good evening everyone. I am seeking for lots of helps, I was working on a online book reservation android application. for some reason (I don't know what's the reason) the application work when I run it on the built-in android emulator. but when I install it on my phone, the books didn't appear. I don't know why it didn't appear on my phone but on the emulator, the books appears. I've follow every steps on how to make an online android application on the YouTube. his application on the tutorials work on his phone but my application didn't work on my phone. please help me everyone.
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
Post the code from your app that does the work to make the book titles appear on the screen. Without that we have less idea of what you are doing wrongly than you have. Better still post a zip file of your complete project.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I've follow every steps on how to make an online android application on the YouTube
What tutorial in Youtube you are talking about?

Please note that an Android app isn´t a Onlineapplication.
For that the app needs to run 24/7. Android apps are not expected to do so.

B4J Server app are.

As @Brian Dean already told: without seeing what code you use it is hard to give any congrete answer. Best is to export your project as zip and upload it.
 
Upvote 0
what i mean is that the books in the database didn't appear when i run/install it on my phone but the books in the database appears when i run/install it on the android emulator on my pc. please help me, i didn't know why it didn't appear on my phone. here's the youtube link:
his/her application works in his/her phone but need internet connection so i consider it as online application.

This is my Source Code, the jRDC2 i use
#Region Project Attributes
#ApplicationLabel: BookReserve Version 1.5
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region

my project on b4a, the whole folder is too large

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type DBResult (Tag As Object, Columns As Map, Rows As List)
Type DBCommand (Name As String, Parameters() As Object)
Private const rdcLink As String = "http://192.168.1.103:17178/rdc"

Dim ImageChooser as ContentChooser
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private StudentBtn As Button
Private TeacherBtn As Button
Private AdminBtn As Button
Private StudentLogInBtn As Button
Private TeacherLogInBtn As Button
Private AdminNum As EditText
Private AdminPass As EditText
Private AdminLogInBtn As Button
Private BackBtn As Button
'SlideMenus
Dim ssm As SSlideMenu
Dim tsm As TSlideMenu
Dim asm As ASlideMenu
'student
Private SSlideMenuPanel As Panel
Private SSlideMenuBtn As Button
Private TabStrip1 As TabStrip
Private ScrollView1 As ScrollView
Private ScrollView2 As ScrollView
Private Panel1 As Panel
Private ListView1 As ListView
'teacher
Private TSlideMenuPanel As Panel
Private TSlideMenuBtn As Button
Private ListView1 As ListView
Private ScrollView1 As ScrollView
Private ScrollView2 As ScrollView
Private Panel1 As Panel
Private TabStrip2 As TabStrip
'admin
Dim asm As ASlideMenu
Private ASlideMenuPanel As Panel
Private ASlideMenuBtn As Button
Dim ssm As SSlideMenu
Dim tsm As TSlideMenu
Dim asm As ASlideMenu
Private Panel1 As Panel
Private TabStrip3 As TabStrip
Private UserTypeCB As B4XComboBox
Private ConditionCB As B4XComboBox
Private IBPanel As Panel
Private RBPanel As Panel
Private IssueBackBtn As Button
Private ReceiveBackBtn As Button
Private ScrollView3 As ScrollView
Private ScrollView4 As ScrollView
Private BookReturnedConditionCB As B4XComboBox
Private AddBtn As Button
Private ImageView1 As ImageView
Private BCNText As EditText
Private BTText As EditText
Private AuthorText As EditText
Private NBText As EditText
Private DescripText As EditText

Dim t,h,w As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK And ssm.isVisible And tsm.isVisible And asm.isVisible Then
ssm.Hide
tsm.Hide
asm.Hide
End If

If KeyCode = KeyCodes.KEYCODE_MENU Then
If ssm.isVisible And tsm.isVisible And asm.isVisible Then
ssm.Hide
tsm.Hide
asm.Hide
Else
ssm.Show
tsm.Show
asm.Hide
End If
End If
Return True
End Sub

'SlideMenu Click
Private Sub SSlideMenuBtn_Click
If ssm.isVisible Then ssm.Hide Else ssm.Show
End Sub

Private Sub TSlideMenuBtn_Click
If tsm.isVisible Then tsm.Hide Else tsm.Show
End Sub

Private Sub ASlideMenuBtn_Click
If asm.isVisible Then asm.Hide Else asm.Show
End Sub
'go to log in
Private Sub StudentBtn_Click
Activity.LoadLayout("StudentLogIn")
End Sub

Private Sub TeacherBtn_Click
Activity.LoadLayout("TeacherLogIn")
End Sub

Private Sub AdminBtn_Click
Activity.LoadLayout("AdminLogIn")
End Sub
'return main layout
Private Sub BackBtn_Click
Activity.LoadLayout("Main")
End Sub
'student
Private Sub StudentLogInBtn_Click
Activity.LoadLayout("StudentHome")

ssm.Initialize(Activity, Me, "SSlideMenu", SSlideMenuPanel.Height, 55%x)

ssm.AddItem("Home", LoadBitmap(File.DirAssets, "Home.png"), 1)
ssm.AddItem("Library", LoadBitmap(File.DirAssets, "library-removebg-preview.png"), 2)
ssm.AddItem("Log Out", LoadBitmap(File.DirAssets, "free-exit-logout-icon-2857-thumb.png"), 3)
End Sub

Sub SSlideMenu_Click (Item As Object)
Select Item
Case 1
ToastMessageShow("Clicked : Home", True)
Activity.LoadLayout("StudentHome")
Case 2
ToastMessageShow("Clicked : Library", True)
Activity.LoadLayout("Library")
TabStrip1.LoadLayout("LibPage1", " Books ")
TabStrip1.LoadLayout("LibPage2", " Borrow Book ")
TabStrip1.LoadLayout("LibPage3", " Return Book ")

TabStrip1_PageSelected(0)

ScrollView1.Panel.LoadLayout("Borrow")
ScrollView2.Panel.LoadLayout("Return")
ScrollView1.Panel.Height = Panel1.Height
ScrollView2.Panel.Height = Panel1.Height

ListView1.TwoLinesAndBitmap.Label.TextSize = 14
ListView1.TwoLinesAndBitmap.Label.TextColor = Colors.Black
ListView1.TwoLinesAndBitmap.Label.Typeface = Typeface.DEFAULT_BOLD
ListView1.TwoLinesAndBitmap.SecondLabel.TextSize = 14
ListView1.TwoLinesAndBitmap.SecondLabel.TextColor = Colors.Gray
ListView1.TwoLinesAndBitmap.ItemHeight = 100dip
ListView1.TwoLinesAndBitmap.ImageView.Gravity = Gravity.NO_GRAVITY
ListView1.TwoLinesAndBitmap.ImageView.Height = 60dip
ListView1.TwoLinesAndBitmap.ImageView.Width = 60dip
ListView1.TwoLinesAndBitmap.ImageView.Top = (ListView1.TwoLinesAndBitmap.ItemHeight/2) - ListView1.TwoLinesAndBitmap.ImageView.Height/2
ListView1.TwoLinesAndBitmap.ImageView.Left = (ListView1.TwoLinesAndBitmap.ItemHeight/2) - ListView1.TwoLinesAndBitmap.ImageView.Height/2
ListView1.TwoLinesAndBitmap.Label.Top = (ListView1.TwoLinesAndBitmap.ItemHeight/2) - (ListView1.TwoLinesAndBitmap.Label.Height)
ListView1.TwoLinesAndBitmap.Label.Left = 100dip
ListView1.TwoLinesAndBitmap.SecondLabel.Top = (ListView1.TwoLinesAndBitmap.ItemHeight/2) - (ListView1.TwoLinesAndBitmap.SecondLabel.Height - 30dip)
ListView1.TwoLinesAndBitmap.SecondLabel.Left = 100dip

SetDivider(ListView1, Colors.LightGray, 1dip)
GetRecord
Case 3
ToastMessageShow("Account Log Out Successful", True)
Activity.LoadLayout("Main")
End Select
End Sub

Sub TabStrip1_PageSelected (Position As Int)
Dim i As Int
For Each lbl As Label In GetAllTabLabels(TabStrip1)
If i = Position Then
lbl.TextColor = Colors.RGB(0,0,0)
Else
lbl.TextColor = Colors.RGB(0,0,0)
End If
i=i+1
Next
End Sub

Public Sub GetAllTabLabels (tabstrip As TabStrip) As List
Dim jo As JavaObject = tabstrip
Dim r As Reflector
r.Target = jo.GetField("tabStrip")
Dim tc As Panel = r.GetField("tabsContainer")
Dim res As List
res.Initialize
For Each v As View In tc
If v Is Label Then res.Add(v)
Next
Return res
End Sub

Sub CreateRequest As DBRequestManager
Dim req As DBRequestManager
req.Initialize(Me, rdcLink)
Return req
End Sub

Sub CreateCommand(Name As String, parameters() As Object) As DBCommand
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = Name
If parameters <> Null Then cmd.Parameters = parameters
Return cmd
End Sub

Sub GetRecord
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("selectedAllItem", Null)
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
If j.Success Then
req.HandleJobAsync(j, "req")
Wait for (req) req_Result(res As DBResult)
'work with result
'req.PrintTable(res)
Log(res.Columns)
ListView1.Clear
For Each row () As Object In res.Rows
Dim oBitMap As Bitmap
Dim buffer() As Byte
buffer = row(res.Columns.Get("BookCover"))
oBitMap = req.BytesToImage(buffer)
ListView1.AddTwoLinesAndBitmap(row(2), row(3) & " See more...", oBitMap)
Next
Else
Log("Error" & j.ErrorMessage)
End If
j.Release
End Sub

Sub SetDivider(lv As ListView, Color As Int, Height As Int)
Dim r As Reflector
r.Target = lv
Dim CD As ColorDrawable
CD.Initialize(Color, 0)
r.RunMethod4("setDivider", Array As Object(CD), Array As String("android.graphics.drawable.Drawable"))
r.RunMethod2("setDividerHeight", Height, "java.lang.int")
End Sub

Private Sub ListView1_ItemClick (Position As Int, Value As Object)

End Sub

Private Sub ListView1_ItemLongClick (Position As Int, Value As Object)

End Sub

'teacher
Private Sub TeacherLogInBtn_Click
Activity.LoadLayout("TeacherHome")

tsm.Initialize(Activity, Me, "TSlideMenu", TSlideMenuPanel.Height, 55%x)

tsm.AddItem("Home", LoadBitmap(File.DirAssets, "Home.png"), 1)
tsm.AddItem("Library", LoadBitmap(File.DirAssets, "library-removebg-preview.png"), 2)
tsm.AddItem("Log Out", LoadBitmap(File.DirAssets, "free-exit-logout-icon-2857-thumb.png"), 3)
End Sub

Sub TSlideMenu_Click (Item As Object)
Select Item
Case 1
ToastMessageShow("Clicked : Home", True)
Activity.LoadLayout("TeacherHome")
Case 2
ToastMessageShow("Clicked : Library", True)
Activity.LoadLayout("libraryy")
TabStrip2.LoadLayout("LibPage1", " Books ")
TabStrip2.LoadLayout("LibPage2", " Borrow Book ")
TabStrip2.LoadLayout("LibPage3", " Return Book ")

TabStrip2_PageSelected(0)

ScrollView1.Panel.LoadLayout("Borrow")
ScrollView2.Panel.LoadLayout("Return")
ScrollView1.Panel.Height = Panel1.Height
ScrollView2.Panel.Height = Panel1.Height

ListView1.TwoLinesAndBitmap.Label.TextSize = 14
ListView1.TwoLinesAndBitmap.Label.TextColor = Colors.Black
ListView1.TwoLinesAndBitmap.Label.Typeface = Typeface.DEFAULT_BOLD
ListView1.TwoLinesAndBitmap.SecondLabel.TextSize = 14
ListView1.TwoLinesAndBitmap.SecondLabel.TextColor = Colors.Gray
ListView1.TwoLinesAndBitmap.ItemHeight = 100dip
ListView1.TwoLinesAndBitmap.ImageView.Gravity = Gravity.NO_GRAVITY
ListView1.TwoLinesAndBitmap.ImageView.Height = 60dip
ListView1.TwoLinesAndBitmap.ImageView.Width = 60dip
ListView1.TwoLinesAndBitmap.ImageView.Top = (ListView1.TwoLinesAndBitmap.ItemHeight/2) - ListView1.TwoLinesAndBitmap.ImageView.Height/2
ListView1.TwoLinesAndBitmap.Label.Top = (ListView1.TwoLinesAndBitmap.ItemHeight/2) - (ListView1.TwoLinesAndBitmap.Label.Height)
ListView1.TwoLinesAndBitmap.Label.Left = 100dip
ListView1.TwoLinesAndBitmap.SecondLabel.Top = (ListView1.TwoLinesAndBitmap.ItemHeight/2) - (ListView1.TwoLinesAndBitmap.SecondLabel.Height - 30dip)
ListView1.TwoLinesAndBitmap.SecondLabel.Left = 100dip

SetDivider(ListView1, Colors.LightGray, 1dip)
GetRecord
Case 3
ToastMessageShow("Account Log Out Successful", True)
Activity.LoadLayout("Main")
End Select
End Sub

Sub TabStrip2_PageSelected (Position As Int)
Dim i As Int
For Each lbl As Label In GetAllTabLabels2(TabStrip2)
If i = Position Then
lbl.TextColor = Colors.RGB(0,0,0)
Else
lbl.TextColor = Colors.RGB(0,0,0)
End If
i=i+1
Next
End Sub

Public Sub GetAllTabLabels2 (tabstrip As TabStrip) As List
Dim jo As JavaObject = tabstrip
Dim r As Reflector
r.Target = jo.GetField("tabStrip")
Dim tc As Panel = r.GetField("tabsContainer")
Dim res As List
res.Initialize
For Each v As View In tc
If v Is Label Then res.Add(v)
Next
Return res
End Sub

'admin
Private Sub AdminLogInBtn_Click
Dim adminNumber As String = AdminNum.Text
Dim adminPassword As String = AdminPass.Text

'Check if the entered credentials match the expected values
If adminNumber = "LibraryAdmin1" And adminPassword = "LibADMIN1234" Then
' Correct credentials, load the AdminHome layout
ToastMessageShow("Login Successful", False)
Activity.LoadLayout("AdminHome")
asm.Initialize(Activity, Me, "ASlideMenu", ASlideMenuPanel.Height, 55%x)

asm.AddItem("Home", LoadBitmap(File.DirAssets, "Home.png"), 1)
asm.AddItem("Library", LoadBitmap(File.DirAssets, "library-removebg-preview.png"), 2)
asm.AddItem("Log Out", LoadBitmap(File.DirAssets, "free-exit-logout-icon-2857-thumb.png"), 3)
Else
' Incorrect credentials, show an error message
ToastMessageShow("Invalid Admin Number or Password", True)
End If
End Sub

'admin
Private Sub IBPanel_Click
Activity.LoadLayout("IssueP1")
ScrollView3.Panel.LoadLayout("IssueP2")
ScrollView3.Panel.Height = Panel1.Height
End Sub

Private Sub RBPanel_Click
Activity.LoadLayout("ReceiveP1")
ScrollView4.Panel.LoadLayout("ReceiveP2")
ScrollView4.Panel.Height = Panel1.Height

BookReturnedConditionCB.SetItems(Array As String("Good","Bad"))
End Sub

Private Sub IssueBackBtn_Click
Activity.LoadLayout("Libraryyy")

TabStrip3.LoadLayout("NewUser", " New User ")
TabStrip3.LoadLayout("NewBook", " New Book ")
TabStrip3.LoadLayout("Issue", " Issue Book ")
TabStrip3.LoadLayout("Receive", "Receive Book ")
UserTypeCB.SetItems(Array As String("Student","Teacher"))
ConditionCB.SetItems(Array As String("Good","Bad"))

TabStrip3_PageSelected(0)
End Sub

Private Sub ReceiveBackBtn_Click
Activity.LoadLayout("Libraryyy")
TabStrip3.LoadLayout("NewUser", " New User ")
TabStrip3.LoadLayout("NewBook", " New Book ")
TabStrip3.LoadLayout("Issue", " Issue Book ")
TabStrip3.LoadLayout("Receive", "Receive Book ")

UserTypeCB.SetItems(Array As String("Student","Teacher"))
ConditionCB.SetItems(Array As String("Good","Bad"))

TabStrip3_PageSelected(0)
End Sub

Sub ASlideMenu_Click (Item As Object)
Select Item
Case 1
ToastMessageShow("Clicked : Home", True)
Activity.LoadLayout("AdminHome")
Case 2
ToastMessageShow("Clicked : Library", True)
Activity.LoadLayout("Libraryyy")
TabStrip3.LoadLayout("NewUser", " New User ")
TabStrip3.LoadLayout("NewBook", " New Book ")
TabStrip3.LoadLayout("Issue", " Issue Book ")
TabStrip3.LoadLayout("Receive", "Receive Book ")

UserTypeCB.SetItems(Array As String("Student","Teacher"))
ConditionCB.SetItems(Array As String("Good","Bad"))

TabStrip3_PageSelected(0)

t = ImageView1.Top
h = ImageView1.Height
w = ImageView1.Width
Case 3
ToastMessageShow("Account Log Out Successful", True)
Activity.LoadLayout("Main")
End Select
End Sub

Sub TabStrip3_PageSelected (Position As Int)
Dim i As Int
For Each lbl As Label In GetAllTabLabels3(TabStrip3)
If i = Position Then
lbl.TextColor = Colors.RGB(0,0,0)
Else
lbl.TextColor = Colors.RGB(0,0,0)
End If
i=i+1
Next
End Sub

Public Sub GetAllTabLabels3 (tabstrip As TabStrip) As List
Dim jo As JavaObject = tabstrip
Dim r As Reflector
r.Target = jo.GetField("tabStrip")
Dim tc As Panel = r.GetField("tabsContainer")
Dim res As List
res.Initialize
For Each v As View In tc
If v Is Label Then res.Add(v)
Next
Return res
End Sub

Private Sub ImageView1_Click
ImageChooser.Initialize("imgChooser")
ImageChooser.Show("image/*","Choose image")
End Sub

Sub imageChooser_Result(Succes As Boolean, Dir As String, FileName As String)
If Succes Then
Dim b As Bitmap
b.Initialize(Dir, FileName)

ImageView1.Bitmap = b

ImageView1.Top = t
ImageView1.Height = h
ImageView1.Width = w

Dim Delta, Height, Width As Int
If b.Width/b.Height > ImageView1.Width/ImageView1.Height Then
Height = b.Height / b.Width * ImageView1.Width
Delta = (ImageView1.Height - Height) / 2
ImageView1.Height = Height
ImageView1.Top = ImageView1.Top + Delta
Else
Width = b.Width / b.Height * ImageView1.Height
Delta = (ImageView1.Width - Width)
ImageView1.Width = Width
ImageView1.Left = ImageView1.Left + Delta
End If
ToastMessageShow("Image Selected", True)
Else
ToastMessageShow("No Image Selected", True)
End If
End Sub

Private Sub AddBtn_Click
If BCNText.Text = "" Or BTText.Text = "" Or AuthorText.Text = "" Or NBText.Text = "" Or DescripText.Text = "" Then
Msgbox("Fill all the needed informations", "failed")
Return
End If
GetSelectedBook(BCNText.Text)
End Sub

Sub CreateRequestAdmin As DBRequestManager
Dim req As DBRequestManager
req.Initialize(Me, rdcLink)
Return req
End Sub

Sub CreateCommandAdmin(Name As String, parameters() As Object) As DBCommand
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = Name
If parameters <> Null Then cmd.Parameters = parameters
Return cmd
End Sub

Sub InsertBook(BookCallNum As String, BookTitle As String, Author As String, NumOfBooks As Int, BookCondition As String, Description As String, BookCover() As Byte)
Dim cmd As DBCommand = CreateCommandAdmin("InsertBook", Array(BookCallNum, BookTitle, Author, NumOfBooks, BookCondition, Description, BookCover))
Dim j As HttpJob = CreateRequestAdmin.ExecuteBatch(Array(cmd), Null)
wait for (j) jobDone(j As HttpJob)
ProgressDialogShow("Please wait")
If j.Success Then
ToastMessageShow("Insert Success", False)
End If
ProgressDialogHide
j.Release
End Sub

Sub GetSelectedBook (NameSelectedItem As String)
Dim req As DBRequestManager = CreateRequestAdmin
Dim cmd As DBCommand = CreateCommandAdmin("selectedBook", Array(NameSelectedItem))
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
ProgressDialogShow("Loading...")
If j.Success Then
req.HandleJobAsync(j, "req")
Wait For(req) req_Result(res As DBResult)
'work with result
'req.Printable(res)
Log(res.Columns)
End If

If res.Rows.Size = 0 Then
Dim bufferI () As Byte
bufferI = CreateRequestAdmin.ImageToBytes(ImageView1.Bitmap)

InsertBook(BCNText.Text, BTText.Text, AuthorText.Text, NBText.Text, ConditionCB.SelectedItem, DescripText.Text, bufferI)
End If

ProgressDialogHide
j.Release
End Sub
 

Attachments

  • .bas,.b4a&androidmanifest.rar
    13.7 KB · Views: 18
  • Files.rar
    32.8 KB · Views: 13
Upvote 0

aeric

Expert
Licensed User
Longtime User
What tutorial in Youtube you are talking about?

Please note that an Android app isn´t a Onlineapplication.
For that the app needs to run 24/7. Android apps are not expected to do so.

B4J Server app are.

As @Brian Dean already told: without seeing what code you use it is hard to give any congrete answer. Best is to export your project as zip and upload it.
Use the </> icon to post your code.
If you are new to this forum, please read: https://www.b4x.com/android/forum/threads/for-new-er-members-how-to-post-a-question-issue.96964/
 
Upvote 0
Top