Android Question Automatic launch of MyLocation after reboot.

Is it possible for an application like MyLocation to automatically continue running after the device is rebooted?

For testing, we will add a timer to the Starter service module. We are not changing anything else in MyLocation!

B4X:
Sub Process_Globals
    Private Timer_Starter As Timer
    Dim Bp As Beeper
End Sub

Let's start the timer.

B4X:
Sub Service_Create
    Timer_Starter.Initialize("Timer_Starter", 5000)
    Timer_Starter.Enabled = True
    Bp.Initialize(50, 400)
End Sub

The timer will work even if you turn off the device.

B4X:
Sub Timer_Starter_Tick
    Log("Timer_Starter_Tick")
    Bp.Beep
End Sub

But if the device is rebooted, the timer will continue to work only if the application is forced to start.

How, then, do applications that receive notifications from the developer server work after a reboot, for example?
 
I tried to create an example of work after rebooting the device and, like John Naylor, I was confused.

The example is extremely simple.

1. I have Android 13.

2. Manifest Contents:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
     android:normalScreens="true"
     android:smallScreens="true"
     android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.

AddPermission(android.permission.RECEIVE_BOOT_COMPLETED)
AddReceiverText(StartupReceiver, <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>)

3. Receiver Module StartupReceiver:

B4X:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
StartReceiverAt(MyReceiver, DateTime.Now + 15 * DateTime.TicksPerMinute, True)
End Sub

4. Receiver Module MyReceiver:
B4X:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)

Log("MyReceiver is working!")

Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo("Test", "Receiver fired - " & cnt, Main)
n.Notify (1)
cnt = cnt + 1
End Sub

That's it, there is nothing else in the Project.
The only goal of the Project: after rebooting the device, receive the intent and call MyReceiver.

I need to make sure that MyReceiver is working in order to perform the actions I need in it.
It would be quite enough for me to send a Notify to the client.

But this doesn't happen. What is the problem?
 
Upvote 0
First step is to understand whether StartupReceiver is started or not. Add some log messages.
Added a log message.

B4X:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)

    Log ("StartupReceiver is working!")

    StartReceiverAt(MyReceiver, DateTime.Now + 15 * DateTime.TicksPerMinute, True)

End Sub

As before: on Android 7 there is logging, on Android 8 or Android 13 there is no logging.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've changed StartupReceiver code to:
B4X:
Sub Process_Globals

End Sub

Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    Log("StartupReceiver")
End Sub
Ran the app in release mode.
Restart the device.
And I see in the logs:
*** Receiver (startupreceiver) Receive (first time) ***
StartupReceiver

Tested on Android 14.
 
Upvote 0
I've changed StartupReceiver code to:
B4X:
Sub Process_Globals

End Sub

Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    Log("StartupReceiver")
End Sub
Ran the app in release mode.
Restart the device.
And I see in the logs:
*** Receiver (startupreceiver) Receive (first time) ***
StartupReceiver

Tested on Android 14.
I do not understand anything.
You just removed StartReceiverAt and didn't change anything else.

I updated to Android 13 today (HyperOS on Xiaomi) and now it works.
But it still doesn't work on another Android 8 device.

What's the matter here?
 
Upvote 0
Top