Android Question Problem with contentchooser and activity_create

Sub7

Active Member
Licensed User
Longtime User
Hi,
it randomly happens that when i pick and image from gallery using the contentchooser the activity is destroyed. How i can prevent this?

I have tried to start a service in foreground when launching the contentchooser and stop the service on success but this does not works for me, it still happends.

Anyone has some working example please? i'm getting frustrated :€

Thanks.
 

Sub7

Active Member
Licensed User
Longtime User
I have read this from @Erel
"If you have a long running task and you don't want the OS to kill your process when there is no visible activity then you should call Service.StartForeground. Android will treat your application as if it is a visible application and will not kill it"

I call this service before executing the contentchooser but my activity still get killed time by time

B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
Dim nb As Notification
End Sub

Sub Service_Create
    nb.Initialize
    nb.Icon=""
    nb.OnGoingEvent = False
    nb.Vibrate=False
    nb.Sound = False
    nb.Notify(0)
    Service.StartForeground(0, nb)
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub


Sub Service_Destroy
'Service.StopForeground(0)
End Sub

Contentchooser

B4X:
Sub btnUpload_Click

Dim q As Int
q= Msgbox2("Upload picture?","Choose","","Cancel", Null)
If q = DialogResponse.POSITIVE Then

    StartService(busyService)
    ImageChooser.show("image/*", "Choose image")

    Else If q = DialogResponse.NEGATIVE Then
       ToastMessageShow("Operation cancelled", True)

    Else If q = DialogResponse.CANCEL Then
        ToastMessageShow("Operation cancelled", True)
    End If
End sub

I load the bitmaps using loadbitmapsample.
 
Upvote 0

Sub7

Active Member
Licensed User
Longtime User
Hello, i changed service_Create in

B4X:
Sub Service_Create
    nb.Initialize
    nb.Icon=""
    nb.OnGoingEvent = True
    nb.Vibrate=False
    nb.Sound = False
    nb.Notify(1)
    Service.StartForeground(1, nb)
End Sub

I see the icon popping out, it seem to work now, no activity_Create in 40 tries.

Thanks =)
 
Upvote 0
Top