Android Question Start Service

RanSoft

Member
Licensed User
Longtime User
Good morning
I need to run in the background a service for notifications.

The service continues if I go out simply from the app - OK
Problems:
If I close the app, the service ends.
It does not start when you start Android, despite #StartBoot.

Download here the source code ...
http://www.ransoft.it/download/notify.zip

Thank you.
 

DonManfred

Expert
Licensed User
Longtime User
If I close the app, the service ends.
It does not start when you start Android, despite #StartBoot.
This is expected in newer android versions. If the User explicitely kills a app then Android will not start the Service unless the user explicitely start the app again.

Don´t kill the app with a taskmanager. LEt android decide when to kill our app (or not)...
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Yes, you can test that workaround : register a broadcast receiver from the Manifest like this

B4X:
AddReceiverText(Your_Service_Name, <intent-filter>
 <action android:name="android.intent.action.BOOT_COMPLETED"/>
 </intent-filter>)

Plus : you have to check if your app is not installed on the external storage (on some phones app installed there won't start at boot)
 
Upvote 0

RanSoft

Member
Licensed User
Longtime User
This is expected in newer android versions. If the User explicitely kills a app then Android will not start the Service unless the user explicitely start the app again.

Don´t kill the app with a taskmanager. LEt android decide when to kill our app (or not)...

But whatsapp, how it works? The notification arrives when it was forcibly closed ...
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
But whatsapp, how it works? The notification arrives when it was forcibly closed ...
The problem with people who don't read advices is that they don't read advices...
Your project is attached.
 

Attachments

  • Notify.zip
    6.4 KB · Views: 162
Upvote 0

RanSoft

Member
Licensed User
Longtime User
I tried to download the attached project, but does not work. The service ends if I close the app forcibly. Does not display more 'ToasMassage.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
That's what DonManfred said : if you kill the app, it will restart only at boot (to be clear : when the phone/tablet is restarted ; subject of your initial question)
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Yes or i wouldn't have send it to you. Sorry if it doesn't work
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
That's what DonManfred said : if you kill the app, it will restart only at boot
DonManfred says this:
If I close the app, the service ends.
It does not start when you start Android, despite #StartBoot.
Therefore, the service will not start at boot.

Here is the test I conducted:
1. Installed and ran in release mode on a device with 4.2.2 OS. runs ok
2. Force close app.
3. Completely power off device.
4. Restart device, app does not restart.

EDIT: if you do not force close the app, the service restarts at boot ok.

Merci
 
Last edited:
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
I am sorry : just made the test to be sure like this :
  1. Start the app with only start at boot. It shows the Toast at internal
  2. Kill the app or by swiping the activity or by the Stop button from Android settings \ Application
  3. Reboot : it won't restart.
  4. Insert the intent receiver in the manifest and do the same
  5. It shows the Toast
  6. Kill the app or by swiping or by the Stop button
  7. Restart the phone : it restarts the service
I can make some video tomorrow if needed (the device is a Homtom HT6 Lollipop).

About the second point : having the service continuing running : by putting the service as sticky one, it continues running if the app is killed by swiping and stops when using the Stop button.
 
Last edited:
Upvote 0
Top