Android Question App-Crash by httputils2service

D

Deleted member 103

Guest
Hi,

when I use this code crashes my app, but not always.
The app can then be terminated only with killing.
What can it be?

B4X:
Private Sub CheckInternetConnection
    Dim job As HttpJob
    job.Initialize("IsInternet", Me)
    job.Download("http://www.google.com")
End Sub

Sub JobDone(Job As HttpJob)   
    If Job.Success Then
        Select Job.JobName
            Case "IsInternet"
                Log("JobDone: Starter.billmanager.GetOwnedProducts")
                Starter.billmanager.GetOwnedProducts
            Case Else
        End Select
    Else
        Log("JobDone: GetOwnedProductsOffline")
        GetOwnedProductsOffline
    End If
    Job.Release
    StopService(HttpUtils2Service)
End Sub

** Activity (main) Pause, UserClosed = false **
Activity_Pause UserClosed=false
** Service (httputils2service) Create **
** Service (httputils2service) Start **
sending message to waiting queue (CallSubDelayed - JobDone)
 

ilan

Expert
Licensed User
Longtime User
Starter.billmanager.GetOwnedProducts should be called if BillingSupported is true

and this is done when Firsttime = true
so when you enter again your app you dont intialize billmanager and your app will crash.

ALSO, if it is firsttime = true and user is not connetected to the net the products he has purchased are retrieve from billmanager.cache so dont worry about that
you only need to tell the app what to do if firsttime is false!

so a simple way to do it, is create a file when user has purchased an item and ask for that file if firsttime is false.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
btw. i have updated a small part in my inapp tutorial that is very important

the billmanager.GetOwnedProducts retrieve all product (purchased, canceled, refunded)
so you should add in the "Sub manager_OwnedProducts" the condition if product is purchased and not canceled or refunded like this:

B4X:
If p.ProductId = "remove_ads" And p.PurchaseState = p.STATE_PURCHASED Then
'...
 
Upvote 0
D

Deleted member 103

Guest
Starter.billmanager.GetOwnedProducts should be called if BillingSupported is true

and this is done when Firsttime = true
so when you enter again your app you dont intialize billmanager and your app will crash.

ALSO, if it is firsttime = true and user is not connetected to the net the products he has purchased are retrieve from billmanager.cache so dont worry about that
you only need to tell the app what to do if firsttime is false!

so a simple way to do it, is create a file when user has purchased an item and ask for that file if firsttime is false.
Hi ilan,
I think the problem is not with "Starter.billmanager.GetOwnedProducts", because I start the "billmanager" from the "starter-Service".
B4X:
Private Sub billmanager_BillingSupported (Supported As Boolean, Message As String)
    Log(Supported & ", " & Message)
    Log("Subscriptions supported: " & billmanager.SubscriptionsSupported)
    IsBillingSupported = Supported
    If Supported Then
        CallSubDelayed (Main, "GetOwnedProducts")
    End If
End Sub

and in "Main" I have these sub:
B4X:
Public Sub GetOwnedProducts
    'Prüfen ob Lizenzprodukten vorhanden sind, aber erst prüfen ob Internet vorhanden.
'    Log("CheckInternetConnection")
'    Log(" ")
    CallSubDelayed(Me, "CheckInternetConnection")
End Sub
 
Upvote 0
D

Deleted member 103

Guest
Can you post the error message? Note that you shouldn't stop httputils2service.
There is no "error message" only the log
** Activity (main) Pause, UserClosed = false **
Activity_Pause UserClosed=false
** Service (httputils2service) Create **
** Service (httputils2service) Start **
sending message to waiting queue (CallSubDelayed - JobDone)
after the log freezes the app and can not be finished normally.
 
Upvote 0
D

Deleted member 103

Guest
Where is the JobDone sub declared? Based on the logs the target module was paused.
Declared is in main activity, but why is the activity paused?

Starter-Service:
B4X:
Service_Create
  billmanager.Initialize("billmanager", key)
End Sub

Private Sub billmanager_BillingSupported (Supported As Boolean, Message As String)
    Log(Supported & ", " & Message)
    Log("Subscriptions supported: " & billmanager.SubscriptionsSupported)
    IsBillingSupported = Supported
    If Supported Then
        CallSubDelayed (Main, "GetOwnedProducts")
    End If
End Sub

main activity:
B4X:
Private Sub billmanager_OwnedProducts (Success As Boolean, purchases As Map)
...
End Sub

Private Sub GetOwnedProductsOffline
...
End Sub

Private Sub SavLizenzFileMap(mp As Map, PurchaseTime As Long)
...
End Sub

Private Sub billmanager_ProductConsumed (Success As Boolean, Product As Purchase)
   'Meldung anzeigen das die Lizenz abgelaufen ist.
   If Success Then
     CallSubDelayed2(Me, "ShowMessageLizenzExpired", Product.ProductId)
   End If
End Sub

Private Sub ShowMessageLizenzExpired(ProductId As String)
...
End Sub

Private Sub billmanager_PurchaseCompleted (Success As Boolean, Product As Purchase)
...
End Sub

Private Sub ShowPurchaseCompleted(ProductId As String)
...
End Sub

Public Sub GetOwnedProducts
   'Prüfen ob Lizenzprodukten vorhanden sind, aber erst prüfen ob Internet vorhanden.
'   Log("CheckInternetConnection")
'   Log(" ")
   CallSubDelayed(Me, "CheckInternetConnection")
End Sub

Private Sub CheckInternetConnection
    Dim job As HttpJob
    job.Initialize("IsInternet", Me)
    job.Download("http://www.google.com")
End Sub

Sub JobDone(Job As HttpJob)   
    If Job.Success Then
        Select Job.JobName
            Case "IsInternet"
                Log("JobDone: Starter.billmanager.GetOwnedProducts")
                Starter.billmanager.GetOwnedProducts
            Case Else
        End Select
    Else
        Log("JobDone: GetOwnedProductsOffline")
        GetOwnedProductsOffline
    End If
    Job.Release
    StopService(HttpUtils2Service)
End Sub
 
Upvote 0
D

Deleted member 103

Guest
I have now initialized billmanager in main-activity, but it does not always work (see log).
The message "Ignoring event: billmanager_billingsupported" I am also very suspicious.
B4X:
Sub Activity_Create(FirstTime As Boolean)
...
    If FirstTime = True Then
        'Log("billmanager Starten")
        Starter.billmanager.Initialize("billmanager", Starter.key)
        Starter.billmanager.DebugLogging = True
    End If
...
End Sub

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for fg.cronomillemiglia_pro
Subscriptions AVAILABLE.
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
Activity_Pause UserClosed=false
Ignoring event: billmanager_billingsupported
** Service (smcrono) Create **
UsbManager wird gestartet!
** Service (smcrono) Start **
** Activity (main) Resume **
WakeLock already held.
SetRaceTime= 0
** Service (smcmm) Create **
** Service (smcmm) Start **
 
Upvote 0
Top