Red-Folder / bgs-core

Core code for the Cordova Background Service
Other
236 stars 105 forks source link

Problem on boot #34

Closed alexandreetf closed 8 years ago

alexandreetf commented 9 years ago

Hi, I'm having problem with the plugin or i i'm doing something wrong.

I installed bgs-sample so i notice two things: 1 - run perfectly app. But when i close app and open again, the option RegisterForUpdate get disabled. Why does this happens? 2 - On boot, the service doesn't start. I'm testing on android 5. I would you like to understand this part of documentation: "To allow for your service to restart after reboot, it is recommended that any configuration of your background service is stored to some form of persistent storage (see Using the configuration)." that can be found here: https://github.com/Red-Folder/bgs-core/wiki/registerForBootStart

alexandreetf commented 9 years ago

My Log console shows: 04-05 22:57:51.502: I/ActivityManager(916): Waited long enough for: ServiceRecord{582d1f6 u0 com.ionicframework.back546619/com.red_folder.phonegap.plugin.backgroundservice.sample.MyService}

Red-Folder commented 9 years ago

Reference your questions;

Reference question 1; Yes, the RegisterForUpdate will be disabled. The app can only be registered for updates during it's lifetime. If you close the app, then it is no longer alive and thus cannot receive automatic updates from the background service.

In a production application, you would automatically register for updates when the App starts. For the sample application I make it all manual so that the developer can see the moving parts.

Reference question 2 - part a - Service doesn't start in boot; Add Log.d() statements to the BootReceiver.java or run in debug (Log.d will probably be easier). This will help us to understand what is happening on boot. I've tested on Android 5 (emulator & device) and both worked fine. I would suspect that there is something within the start up of the background service which is taking too long start - you will need to review your code.

Reference question 2 - part b - Recommendation on persistent storage; The documentation is telling you to use persistent storage for any configuration you use for the background service (either via getConfig/ setConfig or just in your Java code).

The myService sample just uses in-memory variables - so when the service restarts (such as from boot) then it will have lost those in-memory variables.

In production code, any of those variables should be saved to persistent storage (such as shared preferences, SQLite, etc) - so that when the service starts it can read those details back in to the variables.

I hope that all makes sense.

Red-Folder commented 8 years ago

No further activity - assume question closed

ZengYJ commented 8 years ago

Hi. I installed bgs-sample.But The service is not started after device reboot.And I add Log.d in BootReceiver but there is no related any messages in logcat. pls give some help or suggestions. Thks.

Red-Folder commented 8 years ago

@ZengYJ Please do not update closed un-related issues. If you have a new issue to raise, then please create a new one. In the case of you problem - make sure that you have registered it to receive the BootReceive broadcast in the manifest