Bug? RingtoneManager PickerResult Not Called

leongcc

Member
Licensed User
Longtime User
I am running the following example on 2 phones: XiaoMi (4.2.2) and Oppo (4.4.4).
Works correctly at XiaoMi.
Using Oppo and DEBUG mode, after I select the ringtone, PickerResult is not called, B4A WiFi Bridge breaks.
Using Oppo and RELEASE mode, after I select the ringtone, PickerResult is not called, the app goes to Activity_Resume (shown in log).

Did I miss something at manifest OR there is implementation difference in some Android phones, such as Oppo ?


B4X:
Sub Process_Globals
  Dim rm As RingtoneManager
  Dim mp As MediaPlayer
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
  mp.Initialize
  rm.ShowRingtonePicker("rm", rm.TYPE_RINGTONE, True, "")
End Sub

Sub rm_PickerResult (Success As Boolean, Uri As String)
  If Success Then
    If Uri = "" Then
      ToastMessageShow("Silent was chosen", True)
    Else
      mp.Load(rm.GetContentDir, Uri)
      mp.Play
    End If
  Else
    ToastMessageShow("Error loading ringtone.", True)
  End If 
End Sub
 

leongcc

Member
Licensed User
Longtime User
Thanks for responding.
I have difficulty retrieving the log when in RELEASE mode, sometimes it is blank and sometimes it is not even showing application generated logs. Below is the log in DEBUG mode mixed with my application logs so I highlight 4 items and we can ignore the rest.
At the start of the ringtone picker, my Activity is paused. Upon exiting the picker, my Activity resumes immediately without executing PickerResult and the B4A Bridge disconnects abnormally. This does not happen in my other phones.

One other observation is the phone reports no GPS satelite but yet trigger the LocationChanged event.

Do you think my Oppo is a bad implementation of Android or RingtonePicker doesn't return to application properly in in my case ?


B4X:
** Activity (main) Resume **   [<< NOTE: APP STARTS >>]
myGps_LocationChanged
myWifi_FoundReadings
Satellites: Total=0, used=0
Get new reading
Satellites: Total=0, used=0
WebView1 loading done file:///
Satellites: Total=0, used=0
myWifi_FoundReadings
Idle
Satellites: Total=0, used=0
Idle
Satellites: Total=0, used=0
Satellites: Total=0, used=0
Satellites: Total=0, used=0
Idle
Satellites: Total=0, used=0
Get new reading
Satellites: Total=0, used=0
myWifi_FoundReadings
Satellites: Total=0, used=0
myGps_LocationChanged     [<< NOTE: GPS LOCATION CHANGED WITH NO SATELITE >>]
Satellites: Total=0, used=0
Satellites: Total=0, used=0
Satellites: Total=0, used=0
Idle
Satellites: Total=0, used=0
Get new reading
Satellites: Total=1, used=0
myWifi_FoundReadings
Satellites: Total=1, used=0
Satellites: Total=1, used=0
** Activity (main) Pause, UserClosed = false **    [<< NOTE: START PICKER >>]
Ignoring event: btndetectnotisoundselect_up
Satellites: Total=1, used=1
Satellites: Total=1, used=1
Satellites: Total=2, used=1
Get new reading
myGps_LocationChanged
Satellites: Total=2, used=1
Satellites: Total=3, used=1
** Activity (main) Resume **    [<< NOTE: EXIT PICKER >>]
Timeline: Activity_idle id: android.os.BinderProxy@43f10080 time:77733767
 

leongcc

Member
Licensed User
Longtime User
I stripped down my app to the simplest codes that can re-produce the problem.
Apparently, caused by myGps.Start(0,0) at the Starter Service, delete this statement and the Picker will work normally.
Again, only happens to my Oppo phone.


Main:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
  Dim rm As RingtoneManager
  Dim mp As MediaPlayer
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
  mp.Initialize
  rm.ShowRingtonePicker("rm", rm.TYPE_RINGTONE, True, "")
End Sub

Sub rm_PickerResult (Success As Boolean, Uri As String)
  Log("PickerResult")
  If Success Then
    If Uri = "" Then
      ToastMessageShow("Silent was chosen", True)
    Else
      mp.Load(rm.GetContentDir, Uri)
      mp.Play
    End If
  Else
    ToastMessageShow("Error loading ringtone.", True)
  End If
End Sub

Starter Service:
B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: false
#End Region

Sub Process_Globals
    Dim myGps As GPS
End Sub

Sub Service_Create
End Sub

Sub Service_Start (StartingIntent As Intent)
    myGps.Initialize("myGps")
    myGps.Start(0,0)  'This statement causes problem
End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    'Log("Application Error")  'This statement causes problem
    Return True
End Sub

Sub Service_Destroy
End Sub

Sub myGps_LocationChanged (Location1 As Location)
    Log("LocationChanged")
End Sub

Log at DEBUG:
B4X:
Timeline: Activity_launch_request id:b4a.example time:97507412
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
LocationChanged
LocationChanged
LocationChanged
LocationChanged
LocationChanged
** Activity (main) Resume **
Timeline: Activity_idle id: android.os.BinderProxy@439a7380 time:97545278

Log at RELEASE:
B4X:
LogCat connected to: B4A-Bridge: OPPO R8106
--------- beginning of /dev/log/main
Installing file.
PackageAdded: package:b4a.example
 
Last edited:

leongcc

Member
Licensed User
Longtime User
The log in DEBUG is wrong, the app is not supposed to go to Activity_Resume after I select ringtone.
GPS obviously not related to Ringtone Manager. I am reporting here my observation that when GPS starts in Starter-Service, the Ringtone Manager behaves abnormally. Symptoms are: PickerResult event not generated, app restarts by itself. It affects 1 model of phone but I am not sure about the other Android devices that I do not have.
 

leongcc

Member
Licensed User
Longtime User
The Activity is resumed without trapping the PickerResult event, how is this fine?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is how the logs should look:

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
PickerResult
** Activity (main) Resume **

Try to call it from Activity_Click:
B4X:
Sub Activity_Click
   rm.ShowRingtonePicker("rm", rm.TYPE_RINGTONE, True, "")
End Sub
 

leongcc

Member
Licensed User
Longtime User
Thanks.
I really found the cause. It is caused by a feature that some phones have known in different names 'Data Saving', 'Permission Manager', 'Security', etc.. Its like app killer that but built-into the Android OS.
When my app is paused upon branching to Ringtone Manger, it got killed off, so Ringtone Picker cannot return.
 

leongcc

Member
Licensed User
Longtime User
I did that, still got killed.
The only way is to remove GpsStart then it wont get killed.
It is getting strange for me.
 

leongcc

Member
Licensed User
Longtime User
The entire simplest project has already been uploaded at Post#4.
I believe the Main was written by you.
Run it together with the Starter Service in phones that have built-in app killer ('Data Saver', 'Security', 'Permission Manager', etc..).
You may observe that the app is killed when Ringtone Manager is launched, regardless Service is in foreground.
You may also observe the behavior is different when you comment in/out the statement 'myGps.Start(0,0)' that seemingly has nothing to do with anything.
 

leongcc

Member
Licensed User
Longtime User
I added the StartForeground statements to the StarterService.

Thanks for looking into it.
My current temporary solution is to manually switch-off all settings ('Data Saver', 'Security', 'Permission Manager', etc..) that are built-in the phone. I suspect the majority of my users will complain or need guidance if they have to that just to use my app.
 

Attachments

  • RingtonePickerProblem.zip
    430.1 KB · Views: 290
Top