Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crashed on start: Getting error in service #1

Open
vikas442 opened this issue Jun 18, 2019 · 3 comments
Open

Application crashed on start: Getting error in service #1

vikas442 opened this issue Jun 18, 2019 · 3 comments

Comments

@vikas442
Copy link

2019-06-18 13:38:36.253 14693-14693/com.jflavio1.androidmqttexample E/ActivityThread: Service com.jflavio1.androidmqttexample.mqtt.SensorsMqttService has leaked ServiceConnection org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection@327eeb that was originally bound here android.app.ServiceConnectionLeaked: Service com.jflavio1.androidmqttexample.mqtt.SensorsMqttService has leaked ServiceConnection org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection@327eeb that was originally bound here at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1532) at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1424) at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1605) at android.app.ContextImpl.bindService(ContextImpl.java:1557) at android.content.ContextWrapper.bindService(ContextWrapper.java:684) at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:425) at com.jflavio1.androidmqttexample.mqtt.SensorsMqttService.connectToServer(SensorsMqttService.kt:92) at com.jflavio1.androidmqttexample.mqtt.SensorsMqttService.onStartCommand(SensorsMqttService.kt:64) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3474) at android.app.ActivityThread.-wrap20(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 2019-06-18 13:38:39.284 14693-14693/com.jflavio1.androidmqttexample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.jflavio1.androidmqttexample, PID: 14693 android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

@sunilbcone
Copy link

any fix for this issue

@lock-e-box
Copy link

the software works like a charm ...
Above Oreo you need to make a notification channel for the soft to work.

This is very well explained in the following youtube link https://www.youtube.com/watch?v=FbpD5RZtbCc

Once you do this, everything works as expected

-- myapplication --
@OverRide
public void onCreate() {
super.onCreate();
....
createNotificationChannel();
...
}
private void createNotificationChannel(){
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
NotificationChannel serviceChannel = new NotificationChannel(
CHANNEL_ID,
"service channel",
NotificationManager.IMPORTANCE_DEFAULT
);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(serviceChannel);

    }
}

--- MQTTService ---
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
Notification.Builder builder = new Notification.Builder(this, MyApplication.CHANNEL_ID)
.setContentTitle(getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_light)
.setContentText("MQTT Running")
.setAutoCancel(true);

            Notification notification = builder.build();
            startForeground(1, notification);

@jflavio11
Copy link
Owner

Thanks @lock-e-box !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants