Android Service with firebase instance fail to start on BOOT_COMPLETED

279 views
Skip to first unread message

Boniface Chacha

unread,
Mar 17, 2015, 8:19:32 PM3/17/15
to fireba...@googlegroups.com
Hi,

I am new in firebase.
I have a requirement where users will need to receive realtime notifications even if they havent launch the app by clicking it on the android drawer.

I am creating an android app with a background service which need to be started as soon as the android system finish to start (on BOOT_COMPLETED) and STICK alive. The service seem to work fine for earlier version of android (below android 3 ) but fails to work for version 4 higher.
Here is how i initiate firebase in the service:

@Override
public void onCreate() {
 
super.onCreate();

 
Firebase.setAndroidContext(this);
 initFireBase
();
}

private void initFireBase() {
 notifications
= new LinkedList<Notification>();

 
Toast.makeText(this, "Firebase initiated", Toast.LENGTH_LONG).show();
 firebase
= new Firebase("https://incandescent-inferno-2910.firebaseio.com/company-id/notifications/user-id/2015-03-02");
 firebase
.addChildEventListener(this);


 
Log.d("NotificationFirebase", "firebase initiated");
}

UNFORTUNATELY THE SERVICE IS NEVER INITIATED.

Can someone kindly help, I need users to start receive any available notification as long as their mobile phone are on.


Thanks in advance

Frank van Puffelen

unread,
Mar 18, 2015, 3:56:59 PM3/18/15
to fireba...@googlegroups.com
Hi Boniface,

It seems like there was a change in Android 3.1 that prevents services from running at boot time unless the user started the application at least once. See http://stackoverflow.com/a/26026471/209103:

since version Android 3.1+ you don't recieve BOOT_COMPLETE if user never started yor app at least once or user "force closed" application. This was done to prevent malware automaticaly register service. This security hole was closed in newer versions of Android.

Unfortunately if the service is not started, there is no way for Firebase to connect to its servers and retrieve the notifications.

      Frank
Reply all
Reply to author
Forward
0 new messages