This is Erel example, slightly modified to reproduce bug.
Steps to reproduce bug:
1. Start the app (Release).
2. Click home button on your Android device.
3. Find "Home Screen" (Hello World) widget and add widget on your home screen.
4. Click on square button (recent apps) on Android device.
5. Kill all apps by swiping it.
6. Remove widget from home screen.
After this last step event rv_Disabled will NOT be raised.
Starter service is the problem here. If you remove Starter service from project, event will be raised as it should.
I have tested this behavior on Android 7.1.1 and 4.4.2, on both system event is not raised if you follow steps above.
Log:
As you can see in the log Service (widgetservice) Start is raised BEFORE Service (widgetservice) Create. If you remove Starter service, event will be raised in normal order.
Steps to reproduce bug:
1. Start the app (Release).
2. Click home button on your Android device.
3. Find "Home Screen" (Hello World) widget and add widget on your home screen.
4. Click on square button (recent apps) on Android device.
5. Kill all apps by swiping it.
6. Remove widget from home screen.
After this last step event rv_Disabled will NOT be raised.
Starter service is the problem here. If you remove Starter service from project, event will be raised as it should.
I have tested this behavior on Android 7.1.1 and 4.4.2, on both system event is not raised if you follow steps above.
Log:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Service (widgetservice) Create **
** Service (widgetservice) Start **
android.appwidget.action.APPWIDGET_ENABLED
** Service (widgetservice) Start **
android.appwidget.action.APPWIDGET_UPDATE
** Service (starter) Create **
** Service (starter) Start **
** Service (widgetservice) Start **
** Service (widgetservice) Create **
** Service (widgetservice) Start **
android.appwidget.action.APPWIDGET_DELETED
As you can see in the log Service (widgetservice) Start is raised BEFORE Service (widgetservice) Create. If you remove Starter service, event will be raised in normal order.